B
beamguy
Dear Group,
Previously I have described a "feature" of publisher where it positions some elements
in units of points, and other elements in units of pixels. This leads to considerable issues
with formatting when viewing the webpage on a monitor that has a different scaling
between points and pixels than the microsoft default. This program can be used as
a post processor to convert all positions specified in pixels to points. It works well
for me and my webpages. Feel free to distributed it if you see fit.
Regards,
Mike
-----------------------------------------------------------------------------------
#include "stdafx.h"
#include <string.h>
/* If I knew how I could read the screen DPI setting from the registry */
#define MyScreenDPI 96
int main(int argc, char* argv[])
{
FILE *infile,*outfile;
char buf[BUFSIZ],outbuf[BUFSIZ],tempstring[BUFSIZ];
char terms[4][BUFSIZ];
double points;
int i,ipixels,inumber;
strcpy(terms[0],"top:");
strcpy(terms[1],"height:");
strcpy(terms[2],"left:");
strcpy(terms[3],"width:");
if(argc<=1)argv[1]="email.htm";
if((infile=fopen(argv[1],"r")) == NULL)
{
printf("Cannot open input file %s\n",argv[1]);
return 1;
}
if((outfile=fopen("temp.txt","w")) == NULL)
{
printf("Cannot open output file\n");
return 2;
}
/* Read the whole file one line at a time converting pixel information to points */
while(fgets(buf,BUFSIZ,infile) != NULL)
{
/* Loop over search terms */
for (i=0; i<4; i++)
{
strcpy(outbuf,"");
/* While search terms are found on this line convert them */
while(strstr(buf,terms) != NULL)
{
/* This is the pointer to the first character after the search term */
inumber=strstr(buf,terms)-buf+strlen(terms) + 1;
/* Append all preceeding characters into the output buffer */
strncat(outbuf,buf,inumber-1);
/* Remove these characters from buf */
strcpy(tempstring,"");
strncat(tempstring,buf+inumber-1,strlen(buf)-inumber+1);
strcpy(buf,tempstring);
/* Now search for the px term within close proximity */
if(strstr(buf,"px") != NULL)
{
inumber=strstr(buf,"px")-buf;
if(inumber>0 && inumber <=4)
{
/* copy the decimal digits into a temp buffer */
strcpy(tempstring,"");
strncat(tempstring,buf,inumber);
strcat(tempstring,",");
/* Read the integer pixel value from the string */
sscanf(tempstring,"%d",&ipixels);
/* Convert to points */
points=((double)ipixels) * (96.0/MyScreenDPI) * (72.0/96.0);
sprintf(tempstring,"%.1fpt",points);
/* Append the value in points to the output buffer */
strcat(outbuf,tempstring);
/* Now remove the value and the px string from buf */
strcpy(tempstring,"");
strncat(tempstring,buf+inumber+2,strlen(buf)-inumber+1);
strcpy(buf,tempstring);
}
}
}
/* Finish by moving all the remaining characters in buf to the output string*/
strcat(outbuf,buf);
/* Then copy the finished output buffer back into the input buffer */
strcpy(buf,outbuf);
}
/* Now write the modified line to the output file */
fprintf(outfile,"%s",buf);
}
fclose(infile);
fclose(outfile);
/* Now delete the input file and rename the output file */
remove(argv[1]);
rename("temp.txt",argv[1]);
return 0;
}
Previously I have described a "feature" of publisher where it positions some elements
in units of points, and other elements in units of pixels. This leads to considerable issues
with formatting when viewing the webpage on a monitor that has a different scaling
between points and pixels than the microsoft default. This program can be used as
a post processor to convert all positions specified in pixels to points. It works well
for me and my webpages. Feel free to distributed it if you see fit.
Regards,
Mike
-----------------------------------------------------------------------------------
#include "stdafx.h"
#include <string.h>
/* If I knew how I could read the screen DPI setting from the registry */
#define MyScreenDPI 96
int main(int argc, char* argv[])
{
FILE *infile,*outfile;
char buf[BUFSIZ],outbuf[BUFSIZ],tempstring[BUFSIZ];
char terms[4][BUFSIZ];
double points;
int i,ipixels,inumber;
strcpy(terms[0],"top:");
strcpy(terms[1],"height:");
strcpy(terms[2],"left:");
strcpy(terms[3],"width:");
if(argc<=1)argv[1]="email.htm";
if((infile=fopen(argv[1],"r")) == NULL)
{
printf("Cannot open input file %s\n",argv[1]);
return 1;
}
if((outfile=fopen("temp.txt","w")) == NULL)
{
printf("Cannot open output file\n");
return 2;
}
/* Read the whole file one line at a time converting pixel information to points */
while(fgets(buf,BUFSIZ,infile) != NULL)
{
/* Loop over search terms */
for (i=0; i<4; i++)
{
strcpy(outbuf,"");
/* While search terms are found on this line convert them */
while(strstr(buf,terms) != NULL)
{
/* This is the pointer to the first character after the search term */
inumber=strstr(buf,terms)-buf+strlen(terms) + 1;
/* Append all preceeding characters into the output buffer */
strncat(outbuf,buf,inumber-1);
/* Remove these characters from buf */
strcpy(tempstring,"");
strncat(tempstring,buf+inumber-1,strlen(buf)-inumber+1);
strcpy(buf,tempstring);
/* Now search for the px term within close proximity */
if(strstr(buf,"px") != NULL)
{
inumber=strstr(buf,"px")-buf;
if(inumber>0 && inumber <=4)
{
/* copy the decimal digits into a temp buffer */
strcpy(tempstring,"");
strncat(tempstring,buf,inumber);
strcat(tempstring,",");
/* Read the integer pixel value from the string */
sscanf(tempstring,"%d",&ipixels);
/* Convert to points */
points=((double)ipixels) * (96.0/MyScreenDPI) * (72.0/96.0);
sprintf(tempstring,"%.1fpt",points);
/* Append the value in points to the output buffer */
strcat(outbuf,tempstring);
/* Now remove the value and the px string from buf */
strcpy(tempstring,"");
strncat(tempstring,buf+inumber+2,strlen(buf)-inumber+1);
strcpy(buf,tempstring);
}
}
}
/* Finish by moving all the remaining characters in buf to the output string*/
strcat(outbuf,buf);
/* Then copy the finished output buffer back into the input buffer */
strcpy(buf,outbuf);
}
/* Now write the modified line to the output file */
fprintf(outfile,"%s",buf);
}
fclose(infile);
fclose(outfile);
/* Now delete the input file and rename the output file */
remove(argv[1]);
rename("temp.txt",argv[1]);
return 0;
}