"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "swindow/SFontTTF.cpp" between
yudit-3.0.5.tar.gz and yudit-3.0.7.tar.gz

About: yudit is an Unicode plain-text editor that can do True Type font rendering, printing, transliterated keyboard input and handwriting recognition with no dependencies on external engines.

SFontTTF.cpp  (yudit-3.0.5):SFontTTF.cpp  (yudit-3.0.7)
skipping to change at line 67 skipping to change at line 67
static const SString SS_TB_HEAD("head"); static const SString SS_TB_HEAD("head");
static const SString SS_TB_HHEA("hhea"); static const SString SS_TB_HHEA("hhea");
static const SString SS_TB_POST("post"); static const SString SS_TB_POST("post");
static const SString SS_TB_GLYF("glyf"); static const SString SS_TB_GLYF("glyf");
static const SString SS_TB_CMAP("cmap"); static const SString SS_TB_CMAP("cmap");
static const SString SS_TB_KERN("kern"); static const SString SS_TB_KERN("kern");
static const SString SS_TB_MAXP("maxp"); static const SString SS_TB_MAXP("maxp");
static const SString SS_TB_HTMX("hmtx"); static const SString SS_TB_HTMX("hmtx");
static const SString SS_TB_LOCA("loca"); static const SString SS_TB_LOCA("loca");
static const SString SS_TB_OS2("OS/2"); static const SString SS_TB_OS2("OS/2");
static const SString SS_TB_CFF("CFF ");
static const SString SS_TB_CFF2("CFF2");
static const SString SS_TB_COLR("COLR");
static const SString SS_TB_CPAL("CPAL");
/* /*
static const long SS_TN_NOTICE=0; static const long SS_TN_NOTICE=0;
static const long SS_TN_FAMILY=1; static const long SS_TN_FAMILY=1;
static const long SS_TN_WEIGHT=2; static const long SS_TN_WEIGHT=2;
static const long SS_TN_X3=3; static const long SS_TN_X3=3;
*/ */
static const long SS_TN_FULLNAME=4; static const long SS_TN_FULLNAME=4;
//static const long SS_TN_VERSION=5; //static const long SS_TN_VERSION=5;
skipping to change at line 115 skipping to change at line 119
/** /**
* Initialize a TTF * Initialize a TTF
* @param name is the font file * @param name is the font file
*/ */
SFontTTF::SFontTTF (const SFile& _file, const SString& _fontencoding) SFontTTF::SFontTTF (const SFile& _file, const SString& _fontencoding)
: file (_file) : file (_file)
{ {
ok = true; ok = true;
fontencoding = _fontencoding; fontencoding = _fontencoding;
isEmoji = false;
if (fontencoding == "emoji") {
isEmoji = true;
fontencoding.clear();
}
hardWire = SS_NONE; hardWire = SS_NONE;
defaultGlyph = 0; defaultGlyph = 0;
baseGlyph = 0; baseGlyph = 0;
cffFont = 0;
} }
SFontTTF::~SFontTTF () SFontTTF::~SFontTTF ()
{ {
} }
bool bool
SFontTTF::isOK() SFontTTF::isOK()
{ {
if (!ok) return false; if (!ok) return false;
skipping to change at line 249 skipping to change at line 259
return ok; return ok;
} }
/** /**
* initialize all numbers. * initialize all numbers.
* return false if something is wrong with this font. * return false if something is wrong with this font.
*/ */
bool bool
SFontTTF::init () SFontTTF::init ()
{ {
cffFont = 0;
TTF_DIRECTORY* directory = (TTF_DIRECTORY *) image.array(); TTF_DIRECTORY* directory = (TTF_DIRECTORY *) image.array();
if (ntohl (directory->sfntVersion) != 0x00010000) if (ntohl (directory->sfntVersion) == 0x4f54544f) {
cffFont = new SFontCFF();
}
else if (ntohl (directory->sfntVersion) != 0x00010000)
{ {
fprintf (stderr, "SFontTTF: BAD TTF file [%*.*s].\n", SSARGS(name)); fprintf (stderr, "SFontTTF: BAD TTF file [%*.*s] sfntVersion=%x\n",
SSARGS(name), ntohl (directory->sfntVersion));
return false; return false;
} }
TTF_DIR_ENTRY* dir_entry = &(directory->list); TTF_DIR_ENTRY* dir_entry = &(directory->list);
char tag[5]; char tag[5];
unsigned int i; unsigned int i;
for (i=0; i < (unsigned short)ntohs(directory->numTables); i++) for (i=0; i < (unsigned short)ntohs(directory->numTables); i++)
{ {
for (unsigned int j=0; j<4; j++) for (unsigned int j=0; j<4; j++)
{ {
skipping to change at line 441 skipping to change at line 456
* Process the name table * Process the name table
*/ */
bool bool
SFontTTF::processName () SFontTTF::processName ()
{ {
TTF_NAME* name_table = (TTF_NAME*) tables[SS_TB_NAME]; TTF_NAME* name_table = (TTF_NAME*) tables[SS_TB_NAME];
if (name_table==0) if (name_table==0)
{ {
getName (SS_TN_FONTNAME, name.array(), name.size()); getName (SS_TN_FONTNAME, name.array(), name.size());
fprintf (stderr, "SFontTTF: No name fields in %*.*s\n", SSARGS(name)); fprintf (stderr, "SFontTTF: No name fields in %*.*s\n", SSARGS(name));
#if 0
fprintf (stderr, "SFontTTF: records:["); fprintf (stderr, "SFontTTF: records:[");
for (unsigned int i=0; i<tables.size(); i++) for (unsigned int i=0; i<tables.size(); i++)
{ {
for (unsigned int j=0; j<tables.size(i); j++) for (unsigned int j=0; j<tables.size(i); j++)
{ {
SString key = tables.key(i, j); SString key = tables.key(i, j);
fprintf (stderr, " %*.*s", SSARGS(key)); fprintf (stderr, " %*.*s", SSARGS(key));
} }
} }
fprintf (stderr, " ]\n"); fprintf (stderr, " ]\n");
#endif
return false; return false;
} }
TTF_NAME_REC* name_record = &(name_table->nameRecords); TTF_NAME_REC* name_record = &(name_table->nameRecords);
char* string_area = (char *)name_table + ntohs(name_table->offset); char* string_area = (char *)name_table + ntohs(name_table->offset);
int found=0; int found=0;
int i; int i;
for (i=0; i < ntohs (name_table->numberOfNameRecords); i++) for (i=0; i < ntohs (name_table->numberOfNameRecords); i++)
{ {
skipping to change at line 574 skipping to change at line 591
fprintf (stderr, "SFontTTF: BAD TTF file [%*.*s] - indexToLocFormat.\n", fprintf (stderr, "SFontTTF: BAD TTF file [%*.*s] - indexToLocFormat.\n",
SSARGS(name)); SSARGS(name));
return false; return false;
} }
if (tables[SS_TB_HHEA] == 0) if (tables[SS_TB_HHEA] == 0)
{ {
fprintf (stderr, "SFontTTF: BAD hhea table in %*.*s\n", SSARGS(name)); fprintf (stderr, "SFontTTF: BAD hhea table in %*.*s\n", SSARGS(name));
return false; return false;
} }
if (tables[SS_TB_GLYF] == 0) if (cffFont) {
{ if (tables[SS_TB_CFF]) {
fprintf (stderr, "SFontTTF: BAD glyf table in %*.*s\n", SSARGS(name)); if (!cffFont->initWithCFF((SD_BYTE*)tables[SS_TB_CFF])) {
return false; fprintf (stderr, "SFontCFF: initCFF failed %*.*s\n", SSARGS(name));
return false;
}
} else if ( tables[SS_TB_CFF2]) {
if (!cffFont->initWithCFF2((SD_BYTE*)tables[SS_TB_CFF2])) {
fprintf (stderr, "SFontCFF: initCFF2 failed %*.*s\n", SSARGS(name));
return false;
}
} else {
fprintf (stderr, "SFontTTF: has no CFF table %*.*s\n", SSARGS(name));
return false;
}
} else {
if (tables[SS_TB_GLYF] == 0)
{
fprintf (stderr, "SFontTTF: BAD glyf table in %*.*s\n", SSARGS(name));
return false;
}
if (tables[SS_TB_LOCA] == 0)
{
fprintf (stderr, "SFontTTF: BAD loca table in %*.*s\n", SSARGS(name));
return false;
}
}
#if 1
if (tables[SS_TB_COLR] != 0) {
fprintf (stderr, "SFontTTF: COLR font %*.*s\n", SSARGS(name));
} }
if (tables[SS_TB_CPAL] != 0) {
fprintf (stderr, "SFontTTF: CPAL font %*.*s\n", SSARGS(name));
}
#endif
if (tables[SS_TB_CMAP] == 0) if (tables[SS_TB_CMAP] == 0)
{ {
fprintf (stderr, "SFontTTF: BAD cmap table in %*.*s\n", SSARGS(name)); fprintf (stderr, "SFontTTF: BAD cmap table in %*.*s\n", SSARGS(name));
return false; return false;
} }
if (tables[SS_TB_HTMX] == 0) if (tables[SS_TB_HTMX] == 0)
{ {
fprintf (stderr, "SFontTTF: BAD htmx table in %*.*s\n", SSARGS(name)); fprintf (stderr, "SFontTTF: BAD htmx table in %*.*s\n", SSARGS(name));
return false; return false;
} }
if (tables[SS_TB_LOCA] == 0)
{
fprintf (stderr, "SFontTTF: BAD loca table in %*.*s\n", SSARGS(name));
return false;
}
TTF_POST_HEAD* post_table = (TTF_POST_HEAD*) tables[SS_TB_POST]; TTF_POST_HEAD* post_table = (TTF_POST_HEAD*) tables[SS_TB_POST];
if (post_table == 0) if (post_table == 0)
{ {
fprintf (stderr, "SFontTTF: missing post table in %*.*s. Using defaults\n", fprintf (stderr, "SFontTTF: missing post table in %*.*s. Using defaults\n",
SSARGS(name)); SSARGS(name));
italicAngle = 0.0; italicAngle = 0.0;
underlineThickness = 100; underlineThickness = 100;
underlinePosition = 0.0; underlinePosition = 0.0;
isFixedPitch = 0.0; isFixedPitch = 0.0;
} }
skipping to change at line 1063 skipping to change at line 1106
* \brief Get the raw (unscaled) bounding box. * \brief Get the raw (unscaled) bounding box.
* \return true if such a box exists. * \return true if such a box exists.
*/ */
bool bool
SFontTTF::getBBOX (SS_GlyphIndex glyphno, SFontTTF::getBBOX (SS_GlyphIndex glyphno,
int* xMin, int* yMin, int* xMax, int* yMax) const int* xMin, int* yMin, int* xMax, int* yMax) const
{ {
if (glyphno == SD_G_INDIC_ZWJ) return false; if (glyphno == SD_G_INDIC_ZWJ) return false;
if (glyphno == SD_G_INDIC_ZWNJ) return false; if (glyphno == SD_G_INDIC_ZWNJ) return false;
SD_BYTE* gstart = (SD_BYTE *) tables[SS_TB_GLYF]; if (cffFont) {
if (gstart == 0) return false; return cffFont->getBBOXCFF(glyphno, xMin, yMin, xMax, yMax);
}
TTF_GLYF* gtable; TTF_GLYF* gtable;
int len =0; int len =0;
SD_BYTE* gstart = (SD_BYTE *) tables[SS_TB_GLYF];
if (gstart == 0) return false;
if (longOffsets) if (longOffsets)
{ {
SD_ULONG* lloca = (SD_ULONG *) tables[SS_TB_LOCA]; SD_ULONG* lloca = (SD_ULONG *) tables[SS_TB_LOCA];
if (lloca == 0) return false; if (lloca == 0) return false;
unsigned int offs1 = ntohl (lloca[glyphno]); unsigned int offs1 = ntohl (lloca[glyphno]);
unsigned int offs2 = ntohl (lloca[glyphno+1]); unsigned int offs2 = ntohl (lloca[glyphno+1]);
gtable = (TTF_GLYF *) ((char*)gstart + offs1); gtable = (TTF_GLYF *) ((char*)gstart + offs1);
len = offs2-offs1; len = offs2-offs1;
} }
else else
{ {
SD_USHORT* sloca = (SD_USHORT *) tables[SS_TB_LOCA]; SD_USHORT* sloca = (SD_USHORT *) tables[SS_TB_LOCA];
if (sloca == 0) return false; if (sloca == 0) return false;
gtable = (TTF_GLYF *) (gstart + (ntohs (sloca[glyphno]) << 1)); gtable = (TTF_GLYF *) (gstart + (ntohs (sloca[glyphno]) << 1));
len = (ntohs (sloca[glyphno+1]) - ntohs (sloca[glyphno])) << 1; len = (ntohs (sloca[glyphno+1]) - ntohs (sloca[glyphno])) << 1;
} }
if (len <= 0) if (len <= 0)
{ {
return false; return false;
} }
TTF_GLYF* kludge = 0; TTF_GLYF* kludge = 0;
if ((((unsigned long) gtable) & 1) != 0) if ((((unsigned long) gtable) & 1) != 0)
{ {
kludge = new TTF_GLYF[len]; kludge = new TTF_GLYF[len];
CHECK_NEW (kludge); CHECK_NEW (kludge);
skipping to change at line 2757 skipping to change at line 2803
* @param glyphindex is the local glyph index * @param glyphindex is the local glyph index
* @return nothing * @return nothing
*/ */
void void
SFontTTF::drawGlyph (SCanvas* canvas, const SS_Matrix2D& matrix, SFontTTF::drawGlyph (SCanvas* canvas, const SS_Matrix2D& matrix,
SS_GlyphIndex glyphno) SS_GlyphIndex glyphno)
{ {
if (!isOK()) return ; if (!isOK()) return ;
if (glyphno == SD_G_INDIC_ZWJ) return; if (glyphno == SD_G_INDIC_ZWJ) return;
if (glyphno == SD_G_INDIC_ZWNJ) return; if (glyphno == SD_G_INDIC_ZWNJ) return;
TTF_GLYF* gtable = 0;
SD_BYTE* gstart = (SD_BYTE *) tables[SS_TB_GLYF];
TTF_GLYF* gtable;
int len =0; int len =0;
if (cffFont) {
cffFont->drawGlyphCFF(canvas, matrix, glyphno);
return;
}
SD_BYTE* gstart = (SD_BYTE *) tables[SS_TB_GLYF];
if (longOffsets) if (longOffsets)
{ {
SD_ULONG* lloca = (SD_ULONG *) tables[SS_TB_LOCA]; SD_ULONG* lloca = (SD_ULONG *) tables[SS_TB_LOCA];
unsigned int offs1 = ntohl (lloca[glyphno]); unsigned int offs1 = ntohl (lloca[glyphno]);
unsigned int offs2 = ntohl (lloca[glyphno+1]); unsigned int offs2 = ntohl (lloca[glyphno+1]);
gtable = (TTF_GLYF *) ((char*)gstart + offs1); gtable = (TTF_GLYF *) ((char*)gstart + offs1);
len = offs2-offs1; len = offs2-offs1;
} }
else else
{ {
SD_USHORT* sloca = (SD_USHORT *) tables[SS_TB_LOCA]; SD_USHORT* sloca = (SD_USHORT *) tables[SS_TB_LOCA];
gtable = (TTF_GLYF *) (gstart + (ntohs (sloca[glyphno]) << 1)); gtable = (TTF_GLYF *) (gstart + (ntohs (sloca[glyphno]) << 1));
len = (ntohs (sloca[glyphno+1]) - ntohs (sloca[glyphno])) << 1; len = (ntohs (sloca[glyphno+1]) - ntohs (sloca[glyphno])) << 1;
} }
if (len <= 0) if (len <= 0)
{ {
if (!broken && len < 0) if (!broken && len < 0)
{ {
fprintf (stderr, "SFontTTF-2: non-existent glyph %u in %*.*s %d\n", fprintf (stderr, "SFontTTF-2: non-existent glyph %u in %*.*s %d\n",
(unsigned int) glyphno, (unsigned int) glyphno,
SSARGS (name), (int) len) ; SSARGS (name), (int) len) ;
broken = true; broken = true;
} }
return; return;
} }
TTF_GLYF* kludge = 0; TTF_GLYF* kludge = 0;
if ((((unsigned long) gtable) & 1) != 0) if ((((unsigned long) gtable) & 1) != 0)
{ {
if (!broken) if (!broken)
{ {
fprintf (stderr, "SFontTTF: fixing unaligned %*.*s.\n", SSARGS(name)); fprintf (stderr, "SFontTTF: fixing unaligned %*.*s.\n", SSARGS(name));
broken = true; broken = true;
} }
kludge = new TTF_GLYF[len]; kludge = new TTF_GLYF[len];
CHECK_NEW (kludge); CHECK_NEW (kludge);
 End of changes. 19 change blocks. 
30 lines changed or deleted 79 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)