Back to index

tetex-bin  3.0
papersiz.c
Go to the documentation of this file.
00001 /* papersiz.c */
00002 
00003 /************************************************************************
00004 
00005   Part of the dvipng distribution
00006 
00007   This program is free software; you can redistribute it and/or modify
00008   it under the terms of the GNU General Public License as published by
00009   the Free Software Foundation; either version 2 of the License, or
00010   (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful, but
00013   WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018   along with this program; if not, write to the Free Software
00019   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020   02111-1307, USA.
00021 
00022   Copyright (C) 2002-2005 Jan-Åke Larsson
00023 
00024 ************************************************************************/
00025 
00026 #include "dvipng.h"
00027 
00028 const char *lengthnames[]={ "sp", "pt", "bp", 
00029                          "dd", "mm", "pc", 
00030                          "cc", "cm", "in" };
00031 const int32_t lengthsp[]={ 1L, 65536L, 65782L,
00032                         70124L, 186468L, 786432L, 
00033                         841489L, 1864680L, 4736286L };
00034 
00035 /*
00036  *   Convert a double[unit], e.g., "3.2cm" or "1.0in" into length in pixels.
00037  *   Advance the passed pointer as well.
00038  */
00039 
00040 int32_t myatodim(char ** p)
00041 { 
00042   double tmp; /* double accuracy is enough, I think */
00043   int i=0;
00044 
00045   tmp = strtod(*p,p);
00046   while (**p == ' ') 
00047     (*p)++;
00048   while (i<8 && ((*p)[0]!=lengthnames[i][0] || (*p)[1]!=lengthnames[i][1]))
00049     i++; 
00050   if (i==8 && ((*p)[0]!=lengthnames[i][0] || (*p)[1]!=lengthnames[i][1]))
00051     Warning("Unrecognized length unit \"%.2s\", assuming inches.",*p);
00052   while (**p != ',' && **p !='\0')
00053     (*p)++;
00054   tmp *= lengthsp[i]*dpi/4736286L; /* convert sp to pixels */
00055   return((int32_t) tmp);
00056 }
00057 
00058 
00059 /*
00060  *   The routine where we handle the paper size special.  We need to pass in
00061  *   the string after the `papersize=' specification.
00062  */
00063 
00064 void handlepapersize(char * p, int32_t * x, int32_t * y)
00065 { 
00066    while (*p == ' ')
00067       p++ ;
00068    *x = myatodim(&p) ;
00069    while (*p == ' ' || *p == ',')
00070       p++ ;
00071    *y = myatodim(&p) ;
00072 }
00073