This is patch for palmfontconv
first, non unicode related changes:
- fixed compilation on ELF systems
- fixed myalloc(0) problem in togray.c with big fonts (test if InResource is zero)
- topalmtext.c now skips characters not present in source fonts
this makes resulting fonts somewhat smaller and I did not
see any problems with discontinuous glyph ranges in text font format.
Now, unicode related changes:
- topalmtext has now parameter -u, that tells it to loop
through more than first 256 characters (5400 in this patch - read below)
- sample script topluckergray-unicode added. Use it like this:
./topluckergray-unicode palmhi testfont Font.ttf pixelsize
Maximum difference between last and first character is little about 5400.
The reason is that struct GrayFontGlyphInfo has to be present in resource
for each glyph from the range <firstChar, lastChar>, even if the glyph
is not really present in the font. Since sizeof(GrayFontGlyphInfo)==12,
and the resource has to fit into 65536 bytes, we have only 5461 possible
glyphs, and they have to form continuous range. That is rather
unfortunate, since most "interesting" unicode characters are well below
this range, but general punctuation and some other useful characters
(EURO SIGN) are well above. This patch is the maximum we can do while
keeping the current gray fonts format. I propose to extend gray font
format to allow discontinuous glyph ranges in GrayFontGlyphInfo[], while
keeping the fonts backward compatible (given that probably nobody used
fonts with characters above 255 so far).
Proposal:
to use reserved word in GrayFontGlyphInfo like this:
typedef struct {
Int16 leftKerning;
Int16 advance;
UInt16 bitmapWidth;
UInt16 resourceNumber;
UInt16 positionInResourceIndex;
UInt16 glyphNumber;
} GrayFontGlyphInfo;
glyphNumber is the unicode value of given glyph
We than declare that GrayFontGlyphInfo[] contains glyphs in ascending
order, but with skipping permitted. First min(255, lastChar-firstChar)
glyphs has to be continuous, without skipping - this makes new fonts
compatible with older plucker, and older fonts will be usable with
new plucker too (if they do not exceed 256 characters). Plucker, when
drawing character N will first test if N<256. If yes, it will read
GrayFontGlyphInfo directly from corresponding slot of
GrayFontGlyphInfo[] array. If N>=256, GrayFontGlyphInfo will be binary
searched in the rest of the array.
An information about total number of glyphs should be added, too,
since numberOfGlyph!=lastChar-firstChar anymore. For that, some reserved
bytes from GrayFontType can be used.
This still allows only 5400 characters, but from arbitrary UCS2 ranges -
this is more than enough for any use, _with the exception of chinese_ -
for that, GrayFontGlyphInfo[] will probably have to be split into more
resources, but I think we should better leave it for future work.
Please comment.
--
-----------------------------------------------------------
| Radovan Garab�k http://melkor.dnp.fmph.uniba.sk/~garabik/ |
| __..--^^^--..__ garabik @ melkor.dnp.fmph.uniba.sk |
-----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
diff -uN palmfontconv/togray.c palmfontconv-new/togray.c
--- palmfontconv/togray.c 2004-02-10 20:33:29.000000000 +0100
+++ palmfontconv-new/togray.c 2004-03-17 20:09:25.000000000 +0100
@@ -36,8 +36,10 @@
#define LORES 72
#ifdef __ELF__
#define STRNICMP strncasecmp
+#define STRICMP strcasecmp
#else
#define STRNICMP strnicmp
+#define STRICMP stricmp
#endif
#define SWAPBYTES(x,y) { unsigned char __store; __store=(y); (y)=(x); (x)=__store; }
@@ -750,6 +752,8 @@
int pos;
if ( ! ( formats[ i ].mask & toGenerate ) )
continue;
+ if (inResource==0)
+ continue;
sprintf(name, "%s%s%04X.bin", workingDir, formats[ i ].name,
curBitmapResourceID );
msg(3,"Dumping resource file %s [%d items]",name,inResource);
f = myfopen(name, "wb");
@@ -858,7 +862,7 @@
formatsRequested = 0;
while ( i < argc && strcmp( argv[ i ], "-" ) ) {
for ( j = 0 ; j < NUM_FORMATS; j++ )
- if ( ! stricmp( argv[ i ], formats[ j ].name ) ) {
+ if ( ! STRICMP( argv[ i ], formats[ j ].name ) ) {
formatsRequested |= formats[ j ].mask;
break;
}
diff -uN palmfontconv/topalmtext.c palmfontconv-new/topalmtext.c
--- palmfontconv/topalmtext.c 2004-02-10 15:53:43.000000000 +0100
+++ palmfontconv-new/topalmtext.c 2004-03-17 19:58:01.000000000 +0100
@@ -32,6 +32,13 @@
#include <freetype/ftglyph.h>
#include FT_FREETYPE_H
#include "encodings.c"
+#ifdef __ELF__
+#define STRNICMP strncasecmp
+#define STRICMP strcasecmp
+#else
+#define STRNICMP strnicmp
+#define STRICMP stricmp
+#endif
typedef unsigned char Boolean;
typedef unsigned char Byte;
@@ -46,7 +53,7 @@
{
int i;
for ( i = sizeof encodings / sizeof *encodings - 1 ; 0 <= i ; i-- ) {
- if ( !stricmp( encodings[ i ].name, name ) )
+ if ( !STRICMP( encodings[ i ].name, name ) )
break;
}
if ( i < 0 )
@@ -233,13 +240,17 @@
Boolean gray;
Boolean scalable;
Boolean forceL1Chars;
+ Boolean unicodeMode;
int forceEven;
char* encoding = "palmLatin";
+ int topCharNumber;
+
if ( argc < 2 ) {
- fprintf(stderr,"Usage:\n %s [-f] [-e] [-encoding] fontname [pixelSize
[gray]]\n"
+ fprintf(stderr,"Usage:\n %s [-f] [-e] [-u] [-encoding] fontname [pixelSize
[gray]]\n"
" -f : force 0xA0 to be a non-breaking space and 0x85 to be
ellipsis.\n"
" -e : make an attempt to force even width output.\n"
+ " -u : go through all the characters, not just first 256.\n"
" -encoding : set the encoding if the input font is
unicode.\n",argv[0]);
fprintf(stderr,"The following encodings are supported:\n");
for ( i = 0 ; i < NUM_ENCODINGS ; i++ )
@@ -259,6 +270,8 @@
argIndex = 1;
+ unicodeMode = 0;
+
while ( argIndex < argc - 1 && argv[ argIndex ][ 0 ] == '-' ) {
if ( !strcmp( argv[ argIndex ], "-f" ) ) {
forceL1Chars = 1;
@@ -278,11 +291,24 @@
else if ( !strcmp( argv[ argIndex ], "-n-" ) ) {
disableKerning = 0;
}
+ else if ( !strcmp( argv[ argIndex ], "-u-" ) ) {
+ unicodeMode = 0;
+ }
+ else if ( !strcmp( argv[ argIndex ], "-u" ) ) {
+ unicodeMode = 1;
+ }
+
else {
encoding = argv[ argIndex ]+1;
}
argIndex++;
}
+
+ if (unicodeMode)
+/* topCharNumber = 65535; */
+ topCharNumber = 5400;
+ else
+ topCharNumber = 255;
if ( FT_New_Face( library,
argv[ argIndex ],
@@ -335,7 +361,7 @@
highestTop = 0;
lowestBottom = 0;
- for ( i = 0 ; i < 256 ; i++ ) {
+ for ( i = 0 ; i <= topCharNumber ; i++ ) {
/* load glyph image into the slot (erase previous one) */
int c;
if ( forceL1Chars && i == 0xA0 )
@@ -360,7 +386,7 @@
printf( "descent %d\n", -lowestBottom );
printf( "ascent %d\n\n", highestTop );
- for ( i = 0; i < 256; i++ ) {
+ for ( i = 0; i <= topCharNumber; i++ ) {
int c;
int multiplicity;
@@ -373,7 +399,8 @@
}
else
c = i;
- /* load glyph image into the slot (erase previous one) */
+ if ( 0 == FT_Get_Char_Index( face, Decode( c ) ) )
+ continue;
if ( forceEven && scalable )
FT_Set_Pixel_Sizes( face, 0, pixelSize );
if ( FT_Load_Char( face, Decode( c ), FT_LOAD_RENDER | ( gray ?
FT_RENDER_MODE_NORMAL : FT_LOAD_TARGET_MONO ) ) )
diff -uN palmfontconv/topluckergray-unicode palmfontconv-new/topluckergray-unicode
--- palmfontconv/topluckergray-unicode 1970-01-01 01:00:00.000000000 +0100
+++ palmfontconv-new/topluckergray-unicode 2004-03-17 19:49:56.000000000 +0100
@@ -0,0 +1,38 @@
+#! /bin/sh
+# $Id: topluckergray,v 1.9 2003/12/13 16:22:16 arpruss Exp $
+# Convert a font to Plucker Gray scale format
+fname=$2
+if test "X$1" = Xsonyhi; then bitmapversion=1; recordid=0420; boldrecordid=0421;
narrowrecordid=0424; irecordid=0460; iboldrecordid=0461; inarrowrecordid=0464;
versions=GU14; fonttype=NFNT; fi
+if test "X$1" = Xlo; then bitmapversion=1; recordid=0220; boldrecordid=0221;
narrowrecordid=0224; irecordid=0260; iboldrecordid=0261; inarrowrecordid=0264;
versions=GU14; fonttype=NFNT; fi
+if test "X$1" = Xpalmhi; then bitmapversion=3; recordid=0620; boldrecordid=0621;
narrowrecordid=0624; irecordid=0660; iboldrecordid=0661; inarrowrecordid=0664;
versions=GU34; fonttype=nfnt; fi
+if test "X$1" = Xsonyhi.right; then bitmapversion=1; recordid=0420;
boldrecordid=0421; narrowrecordid=0424; irecordid=0460; iboldrecordid=0461;
inarrowrecordid=0464; versions="GU14 GR14"; fonttype=NFNT; fi
+if test "X$1" = Xlo.right; then bitmapversion=1; recordid=0220; boldrecordid=0221;
narrowrecordid=0224; irecordid=0260; iboldrecordid=0261; inarrowrecordid=0264;
fonttype=NFNT; versions="GU14 GR14"; fi
+if test "X$1" = Xpalmhi.right; then bitmapversion=3; recordid=0620;
boldrecordid=0621; narrowrecordid=0624; irecordid=0660; iboldrecordid=0661;
inarrowrecordid=0664; fonttype=nfnt; versions="GU34 GR34"; fi
+if test "X$1" = Xsonyhi.left; then bitmapversion=1; recordid=0420; boldrecordid=0421;
narrowrecordid=0424; irecordid=0460; iboldrecordid=0461; inarrowrecordid=0464;
versions="GU14 GL14"; fonttype=NFNT; fi
+if test "X$1" = Xlo.left; then bitmapversion=1; recordid=0220; boldrecordid=0221;
narrowrecordid=0224; irecordid=0260; iboldrecordid=0261; inarrowrecordid=0264;
fonttype=NFNT; versions="GU14 GL14"; fi
+if test "X$1" = Xpalmhi.left; then bitmapversion=3; recordid=0620; boldrecordid=0621;
narrowrecordid=0624; irecordid=0660; iboldrecordid=0661; inarrowrecordid=0664;
fonttype=nfnt; versions="GU34 GL34"; fi
+if test "X$1" = Xsonyhi.both; then bitmapversion=1; recordid=0420; boldrecordid=0421;
narrowrecordid=0424; irecordid=0460; iboldrecordid=0461; inarrowrecordid=0464;
versions="GU14 GL14 GR13"; fonttype=NFNT; fi
+if test "X$1" = Xlo.both; then bitmapversion=1; recordid=0220; boldrecordid=0221;
narrowrecordid=0224; irecordid=0260; iboldrecordid=0261; inarrowrecordid=0264;
fonttype=NFNT; versions="GU14 GL14 GR14"; fi
+if test "X$1" = Xpalmhi.both; then bitmapversion=3; recordid=0620; boldrecordid=0621;
narrowrecordid=0624; irecordid=0660; iboldrecordid=0661; inarrowrecordid=0664;
fonttype=nfnt; versions="GU34 GL34 GR34"; fi
+depth=4
+if test "X$bitmapversion" = X; then echo "topluckergray
lo|palmhi|sonyhi[.right|.left|.both] dbname inputfilename pixelsize [inputfilename
boldpixelsize [inputfilename narrowpixelsize]]"; exit; fi
+rm G*.bin nfnt*.bin NFNT*.bin 2> /dev/null
+echo Processing outline fonts...
+if ! ./topalmtext -u -f $3 $4 gray > topluckergray-font.txt; then echo "Error
processing"; exit; fi
+if test "X$6" != X; then echo \(bold\)...; ./topalmtext -u -f $5 $6 gray >
topluckergray-boldfont.txt; extra_args="- $fonttype$boldrecordid
topluckergray-boldfont.txt $versions"; fi
+if test "X$8" != X; then echo \(narrow\)...; ./topalmtext -u -f $7 $8 gray >
topluckergray-narrowfont.txt; extra_args2="- $fonttype$narrowrecordid
topluckergray-narrowfont.txt $versions"; fi
+shift
+shift
+if test "X$8" != X; then echo \(italic\)...; ./topalmtext -u -f $7 $8 gray >
topluckergray-italicfont.txt; extra_args3="- $fonttype$irecordid
topluckergray-italicfont.txt $versions"; fi
+shift
+shift
+if test "X$8" != X; then echo \(bold italic\)...; ./topalmtext -u -f $7 $8 gray >
topluckergray-bolditalicfont.txt; extra_args4="- $fonttype$iboldrecordid
topluckergray-bolditalicfont.txt $versions"; fi
+shift
+shift
+if test "X$8" != X; then echo \(narrow italic\)...; ./topalmtext -u -f $7 $8 gray >
topluckergray-narrowitalicfont.txt; extra_args5="- $fonttype$inarrowrecordid
topluckergray-narrowitalicfont.txt $versions"; fi
+echo Generating Plucker bitmaps in versions $versions...
+./togray $fonttype$recordid topluckergray-font.txt $versions $extra_args $extra_args2
$extra_args3 $extra_args4 $extra_args5
+#par c -a "resource|backup" $fname.prc "$fname" Font Plkr *.bin
+echo Making prc
+./toprc $fname.prc "$fname" Font Plkr *.bin
+
diff -uN palmfontconv/toremap.c palmfontconv-new/toremap.c
--- palmfontconv/toremap.c 2003-11-27 17:11:20.000000000 +0100
+++ palmfontconv-new/toremap.c 2004-02-23 20:23:46.000000000 +0100
@@ -1,6 +1,14 @@
#include <stdio.h>
#include <string.h>
+#ifdef __ELF__
+#define STRNICMP strncasecmp
+#define STRICMP strcasecmp
+#else
+#define STRNICMP strnicmp
+#define STRICMP stricmp
+#endif
+
struct {
char* name;
unsigned short fontID;
@@ -51,7 +59,7 @@
fontID = 0;
if ( argc == 3 ) {
for ( i = 0 ; i < NUM_FONTS ; i++ ) {
- if ( !stricmp( argv[2], fontList[i].name ) ) {
+ if ( !STRICMP( argv[2], fontList[i].name ) ) {
fontID = fontList[i].fontID;
fprintf( stderr, "%s --> %x\n",argv[2],fontID );
}