Web Design Web Design Forum
Registration is free! Here you can view your subscribed threads, work with private messages and edit your profile and preferences Calendar Find other members Frequently Asked Questions Search
Home Web Design

Convenient web based access to our favorite web design Usenet groups

web design reviews

This is Interesting: Free Magazines for Graphics designers and webmasters  





  Last Thread  Next Thread
Author
Thread Post New Thread   

C program that converts all object positioning in HTML from pixels to points - helps c
 

beamguy




quote this post edit post

IP Loged report this post

Old Post  05-25-06 - 03:58 AM  
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 con
siderable issues
with formatting when viewing the webpage on a monitor that has a different s
caling
between points and pixels than the microsoft default. This program can be us
ed 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 po
ints */
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[i]) != NULL)
{
/* This is the pointer to the first character after the search term */
inumber=strstr(buf,terms[i])-buf+strlen(terms[i]) + 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;
}




Post Follow-Up to this message ]
Sponsored Links
 





All times are GMT. The time now is 05:50 AM. Post New Thread   
  Previous Last Thread   Next Thread next
Microsoft Publisher archive | Show Printable Version | Email this Page | Subscribe to this Thread

Popular forums

Adobe Photoshop forum Macromedia Flash Web Site Design
Dreamweaver FrontPage forum
JavaScript Forum XML forum
Style Sheets VRML
Forum Jump:
Rate This Thread:

 

XML RSS Feed web design latest articles Syndicate our forum via XML or simple JavaScript

Web Design archive  Database administration help  


Top Home  -  Register  -  Control Panel   -  Memberlist  -  Calendar  -  Faq  -  Search Top