Index: classlib/modules/awt/src/main/native/fontlib/shared/ParsingTables.cpp =================================================================== --- classlib/modules/awt/src/main/native/fontlib/shared/ParsingTables.cpp (révision 949175) +++ classlib/modules/awt/src/main/native/fontlib/shared/ParsingTables.cpp (copie de travail) @@ -853,311 +853,530 @@ return 0; } -fint parseGlyphData(FILE* tt_file, const GlyphOffsets gO, ufshort numGlyphs, ufshort glyphIndex, TTCurve *curve, fshort* bRect, ffloat transform) +static fint parseSimpleGlyphData(FILE* tt_file, TTCurve *curve, ffloat transform, fint numOfContours); + +fint parseCompositeGlyphData(TTFont *tt_font, FILE* tt_file, TTCurve *curve, ffloat transform, ufshort glyphSize, ufshort *metricsIndex, ufshort unitsPerEm); + +fint parseGlyphData(TTFont *tt_font, FILE* tt_file, const GlyphOffsets gO, ufshort numGlyphs, ufshort glyphIndex, TTCurve *curve, fshort* bRect, ffloat transform, ufshort glyphSize, ufshort *metricsIndex, ufshort unitsPerEm) { - uflong offset; - Glyph_header glyphHeader; - fshort numOfContours; - ufshort *endPtsOfContours = NULL; - ufshort instructionLength;//instruction length in bytes - ufchar* instructions = NULL; - ufchar* flags = NULL; - ufchar* xCoord = NULL; //pointer to array of X coordinates - ufchar* yCoord = NULL; //pointer to array of Y coordinates - ufchar* tmp = NULL; + uflong offset; + Glyph_header glyphHeader; + fshort numOfContours; - fint numPoints; // number of Points - fint size, i, j, curLen; - fint flagIndex = 0; - fint xCoordIndex = 0; - fint yCoordIndex = 0; - fint rep = 0; + fint size; - fshort xLength = 0; //length of array of X coordinates - fshort yLength = 0; //length of array of Y coordinates - ufchar curFlag = 0; + if (glyphIndex >= numGlyphs) + { +// printf("debug info: glyphIndex out of range"); + glyphIndex = 0; + } - if (glyphIndex >= numGlyphs) - { -// printf("debug info: glyphIndex out of range"); - glyphIndex = 0; - } + offset = gO.offsets[glyphIndex]; + if (offset == gO.offsets[glyphIndex+1]) + { + curve->add(0,0, 1); + return 0; + } - offset = gO.offsets[glyphIndex]; - if (offset == gO.offsets[glyphIndex+1]) - { - curve->add(0,0, 1); - return 0; - } + size = fseek(tt_file, offset, SEEK_SET); + if (size != 0){ +// printf("Error executing fseek() for someone glyph."); + return -1; + } - size = fseek(tt_file, offset, SEEK_SET); - if (size != 0){ -// printf("Error executing fseek() for someone glyph."); - return -1; - } + /* read 'Glyph_header' table */ + size = (fint)fread(&glyphHeader, sizeof(Glyph_header), 1, tt_file); + if (size != 1){ +// printf("Error reading 'Glyph_header' table from file."); + return -1; + } - /* read 'Glyph_header' table */ - size = (fint)fread(&glyphHeader, sizeof(Glyph_header), 1, tt_file); - if (size != 1){ -// printf("Error reading 'Glyph_header' table from file."); - return -1; - } + glyphHeader.number_of_contours = wReverse(glyphHeader.number_of_contours); + numOfContours = glyphHeader.number_of_contours; + bRect[0] = (short)(wReverse(glyphHeader.xMin)*transform); + bRect[1] = (short)(wReverse(glyphHeader.yMin)*transform); + bRect[2] = (short)(wReverse(glyphHeader.xMax)*transform); + bRect[3] = (short)(wReverse(glyphHeader.yMax)*transform); - glyphHeader.number_of_contours = wReverse(glyphHeader.number_of_contours); - numOfContours = glyphHeader.number_of_contours; - bRect[0] = (short)(wReverse(glyphHeader.xMin)*transform); - bRect[1] = (short)(wReverse(glyphHeader.yMin)*transform); - bRect[2] = (short)(wReverse(glyphHeader.xMax)*transform); - bRect[3] = (short)(wReverse(glyphHeader.yMax)*transform); - - if (numOfContours > 0) - { - endPtsOfContours = new ufshort[numOfContours]; - size = (fint)fread(endPtsOfContours, sizeof(fshort),numOfContours,tt_file); - if (size != numOfContours) - { -// printf("Error reading endPtsOfContours for someone glyph."); - delete[] endPtsOfContours; - return -1; - } + if (numOfContours >= 0) + { + return parseSimpleGlyphData(tt_file, curve, transform, numOfContours); + }else if (numOfContours == -1) + { + return parseCompositeGlyphData(tt_font, tt_file, curve, transform, glyphSize, metricsIndex, unitsPerEm); + } + return -1; +} - for (i=0; i1) && !(curFlag & ON_CURVE ) && - ((rep == 1) ? (!(flags[flagIndex-2] & ON_CURVE)) : (!(flags[flagIndex-3] & ON_CURVE)))) - curve->add((x+xChange/2)*transform,(y+yChange/2)*transform,FLAG_ONCURVE); + if((flagIndex >1) && !(curFlag & ON_CURVE ) && + ((rep == 1) ? (!(flags[flagIndex-2] & ON_CURVE)) : (!(flags[flagIndex-3] & ON_CURVE)))) + curve->add((x+xChange/2)*transform,(y+yChange/2)*transform,FLAG_ONCURVE); - x+=xChange; - y+=yChange; + x+=xChange; + y+=yChange; - if (contBegin) - { - curve->add(x*transform,y*transform, 1); - xFirstInContour = x*transform; - yFirstInContour = y*transform; + if (contBegin) + { + curve->add(x*transform,y*transform, 1); + xFirstInContour = x*transform; + yFirstInContour = y*transform; - contBegin = 0; - } else - curve->add(x*transform,y*transform, curFlag & ON_CURVE ? FLAG_ONCURVE : 0); + contBegin = 0; + } else + curve->add(x*transform,y*transform, curFlag & ON_CURVE ? FLAG_ONCURVE : 0); - rep--; - i++; - } - curve->add(xFirstInContour,yFirstInContour,FLAG_ONCURVE); - } - } + rep--; + i++; + } + curve->add(xFirstInContour,yFirstInContour,FLAG_ONCURVE); + } - delete[] xCoord; - delete[] yCoord; - delete[] flags; - delete[] endPtsOfContours; - delete[] instructions; + delete[] xCoord; + delete[] yCoord; + delete[] flags; + delete[] endPtsOfContours; + delete[] instructions; - return 0; + return 0; } -/* Should be removed when the composite glyph parsing will be realized */ -bool isCompositeGlyph(FILE* tt_file, const GlyphOffsets gO, ufshort numGlyphs, ufshort glyphIndex) +static inline ffloat f2dot14(fshort s) { - uflong offset; - Glyph_header glyphHeader; + return wReverse(s) / (ffloat) 16384; +} - fint size; +static inline ffloat abs(ffloat f) +{ + return f < 0 ? -f : f; +} - if (glyphIndex >= numGlyphs) - glyphIndex = 0; +static inline ffloat max(ffloat a, ffloat b) +{ + return a < b ? b : a; +} - offset = gO.offsets[glyphIndex]; - if (offset == gO.offsets[glyphIndex+1]) - return false; +fint parseCompositeGlyphData(TTFont *tt_font, FILE* tt_file, TTCurve *curve, ffloat transform, ufshort glyphSize, ufshort *metricsIndex, ufshort unitsPerEm) +{ + TTGlyph *glyph; + ufshort flags; + ufshort glyphIndex; + fshort tmp; + fchar tmpC; + ufshort idComponent, idComposite; + ufchar tmpUC; + ffloat xOffset, yOffset, xScale, yScale, scale01, scale10; + fshort i_xOffset, i_yOffset; -/*printf("glyphIndex = %d\n",glyphIndex); -if (tt_file == NULL) -printf("file is NULL\n"); -else -printf("file isn't NULL\n");*/ - size = fseek(tt_file, offset, SEEK_SET); - if (size != 0) -{ -//printf("return false\n"); - return false; + fint size; + bool scaleOffset; + do + { + size = fread(&flags, sizeof(fshort), 1, tt_file); + if (size != 1) { +#ifdef BEBUG + printf("Error reading flags for composite glyph\n"); +#endif + return -1; + } + flags = wReverse(flags); + size = fread(&glyphIndex, sizeof(fshort), 1, tt_file); + if (size != 1) { +#ifdef DEBUG + printf("Error reading component index for composite glyph\n"); +#endif + return -1; + } + glyphIndex = wReverse(glyphIndex); + glyph = tt_font->getGlyphByIndex(glyphIndex, glyphSize); + if ((flags & ARGS_ARE_XY_VALUES) == ARGS_ARE_XY_VALUES) + { + scaleOffset = true; + if ((flags & ARG_1_AND_2_ARE_WORDS) == ARG_1_AND_2_ARE_WORDS) + { + size = fread(&i_xOffset, sizeof(fshort), 1, tt_file); + if (size != 1){ +#ifdef DEBUG + printf("Error reading args for composite glyph\n"); +#endif + return -1; + } + i_xOffset = wReverse(i_xOffset); + size = fread(&i_yOffset, sizeof(fshort), 1, tt_file); + if (size != 1){ +#ifdef DEBUG + printf("Error reading args for composite glyph\n"); +#endif + return -1; + } + i_yOffset = wReverse(i_yOffset); + }else + { + size = fread(&tmpC, sizeof(fchar), 1, tt_file); + if (size != 1){ +#ifdef DEBUG + printf("Error reading args for composite glyph\n"); +#endif + return -1; + } + i_xOffset = (fshort) tmpC; + size = fread(&tmpC, sizeof(fchar), 1, tt_file); + if (size != 1){ +#ifdef DEBUG + printf("Error reading args for composite glyph\n"); +#endif + return -1; + } + i_yOffset = (fshort) tmpC; + } + xOffset = (ffloat) i_xOffset; + yOffset = (ffloat) i_yOffset; + // TODO Use flag ROUND_XY_TO_GRID + }else + { + scaleOffset = false; + if ((flags & ARG_1_AND_2_ARE_WORDS) == ARG_1_AND_2_ARE_WORDS) + { + size = fread(&idComposite, sizeof(fshort), 1, tt_file); + if (size != 1){ +#ifdef DEBUG + printf("Error reading args for composite glyp\n"); +#endif + return -1; + } + idComposite = wReverse(idComposite); + size = fread(&idComponent, sizeof(fshort), 1, tt_file); + if (size != 1){ +#ifdef DEBUG + printf("Error reading args for composite glyp\n"); +#endif + return -1; + } + idComponent = wReverse(idComponent); + }else + { + size = fread(&tmpUC, sizeof(fchar), 1, tt_file); + if (size != 1){ +#ifdef DEBUG + printf("Error reading args for composite glyp\n"); +#endif + return -1; + } + idComposite = (ufshort)tmpUC; + size = fread(&tmpUC, sizeof(fchar), 1, tt_file); + if (size != 1){ +#ifdef DEBUG + printf("Error reading args for composite glyp\n"); +#endif + return -1; + } + idComponent = (ufshort)tmpUC; + } + xOffset = curve->_coords[idComponent*2] - glyph->_curve->_coords[idComposite*2]; + yOffset = curve->_coords[idComponent*2+1] - glyph->_curve->_coords[idComposite*2+1]; + } + + if ((flags & USE_MY_METRICS) == USE_MY_METRICS) + { + *metricsIndex = glyphIndex; + } + if ((flags & WE_HAVE_A_TWO_BY_TWO) == WE_HAVE_A_TWO_BY_TWO) + { + size = fread(&tmp, sizeof(fshort), 1, tt_file); + if (size != 1) { +#ifdef DEBUG + printf("Error reading scale args for composite glyp\n"); +#endif + return -1; + } + xScale = f2dot14(tmp); + size = fread(&tmp, sizeof(fshort), 1, tt_file); + if (size != 1) { +#ifdef DEBUG + printf("Error reading scale args for composite glyp\n"); +#endif + return -1; + } + scale01 = f2dot14(tmp); + size = fread(&tmp, sizeof(fshort), 1, tt_file); + if (size != 1) { +#ifdef DEBUG + printf("Error reading scale args for composite glyp\n"); +#endif + return -1; + } + scale10 = f2dot14(tmp); + size = fread(&tmp, sizeof(fshort), 1, tt_file); + if (size != 1) { +#ifdef DEBUG + printf("Error reading scale args for composite glyp\n"); +#endif + return -1; + } + yScale = f2dot14(tmp); + if (scaleOffset) + { + if (abs(abs(xScale) - abs(scale10)) <= ((ffloat)33/65536)) + xOffset *= 2; + if (abs(abs(scale10) - abs(yScale)) <= ((ffloat)33/65536)) + yOffset *= 2; + xOffset *= abs(abs(xScale) - abs(scale01)) * transform; + yOffset *= abs(abs(scale10) - abs(yScale)) * transform; + } + }else + { + if ((flags & WE_HAVE_A_SCALE) == WE_HAVE_A_SCALE) + { + size = fread(&tmp, sizeof(fshort), 1, tt_file); + if (size != 1) { +#ifdef DEBUG + printf("Error reading scale args for composite glyp\n"); +#endif + return -1; + } + xScale = f2dot14(tmp); + yScale = xScale; + }else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) == WE_HAVE_AN_X_AND_Y_SCALE) + { + size = fread(&tmp, sizeof(fshort), 1, tt_file); + if (size != 1) { +#ifdef DEBUG + printf("Error reading scale args for composite glyp\n"); +#endif + return -1; + } + xScale = f2dot14(tmp); + size = fread(&tmp, sizeof(fshort), 1, tt_file); + if (size != 1) { +#ifdef DEBUG + printf("Error reading scale args for composite glyp\n"); +#endif + return -1; + } + yScale = f2dot14(tmp); + } + else + { + xScale = 1; + yScale = 1; + } + + scale01 = 0; + scale10 = 0; + + if (scaleOffset) + { + xOffset *= xScale * transform; + yOffset *= yScale * transform; + } + } + curve->merge(glyph->_curve, xOffset, yOffset, xScale, yScale, scale01, scale10); + } while ((flags & MORE_COMPONENTS) == MORE_COMPONENTS); + return 0; + // TODO check instructions } -//printf("second return\n"); - /* read 'Glyph_header' table */ - size = (fint)fread(&glyphHeader, sizeof(Glyph_header), 1, tt_file); - if (size != 1) - return false; -//printf("third return\n"); - return wReverse(glyphHeader.number_of_contours) < 0; -} Index: classlib/modules/awt/src/main/native/fontlib/shared/TTCurve.h =================================================================== --- classlib/modules/awt/src/main/native/fontlib/shared/TTCurve.h (révision 949175) +++ classlib/modules/awt/src/main/native/fontlib/shared/TTCurve.h (copie de travail) @@ -37,7 +37,7 @@ ufshort _outlineCommandsNumb; fint add(ffloat x, ffloat y, ufchar flag); - + fint merge(TTCurve* curve, ffloat xOffset, ffloat yOffset, ffloat xScale, ffloat yScale, ffloat scale01, ffloat scale10); }; #endif Index: classlib/modules/awt/src/main/native/fontlib/shared/Font.cpp =================================================================== --- classlib/modules/awt/src/main/native/fontlib/shared/Font.cpp (révision 949175) +++ classlib/modules/awt/src/main/native/fontlib/shared/Font.cpp (copie de travail) @@ -115,6 +115,22 @@ return glyph; } +void Font::registerGlyph(Glyph* glyph) +{ + registerGlyph(glyph, (glyph->_size << 16) + glyph->_unicode); +} + +inline void Font::registerGlyph(Glyph* glyph, const uflong id) +{ + _glyphMap[id] = glyph; +} + + +Glyph* Font::getGlyphByIndex(ufshort index, ufshort size) +{ + return getGlyph(getUnicodeByIndex(index), size); +} + // Creation of font depending on font type Font* createFont(fchar* family, StyleName sn) { fint nLen = (fint) strlen(family); Index: classlib/modules/awt/src/main/native/fontlib/shared/Font.h =================================================================== --- classlib/modules/awt/src/main/native/fontlib/shared/Font.h (révision 949175) +++ classlib/modules/awt/src/main/native/fontlib/shared/Font.h (copie de travail) @@ -59,6 +59,7 @@ virtual ~Font(); Glyph* getGlyph(ufshort unicode, ufshort size); + Glyph* getGlyphByIndex(ufshort index, ufshort size); Glyph* getDefaultGlyph(); fint getMissingGlyphCode(); @@ -86,12 +87,14 @@ ufshort _size; std::map _glyphMap;//(size << 16 + unicode) -- Glyph Flags _flags; + void registerGlyph(Glyph* glyph); // virtual ufshort* getBitmap(); // virtual ufshort* getOutline(); // virtual ufshort* getGlyph(); private: inline Glyph* findGlyph(ufshort unicode, ufshort size, uflong id); + inline void registerGlyph(Glyph* glyph, const uflong id); }; Font* createFont(fwchar_t* family, StyleName sn); Index: classlib/modules/awt/src/main/native/fontlib/shared/TTFont.cpp =================================================================== --- classlib/modules/awt/src/main/native/fontlib/shared/TTFont.cpp (révision 949175) +++ classlib/modules/awt/src/main/native/fontlib/shared/TTFont.cpp (copie de travail) @@ -28,26 +28,25 @@ _glyphOffsets.offsets = NULL; _tableEncode.TableEncode = NULL; _famName = NULL; - _ttfile = NULL; _hMetrics = NULL; _psName = NULL; - _ttfile = fopen(_pathToFile,"rb"); - parseNameTable(_ttfile, &_famName, &_psName, NULL); - parseCmapTable(_ttfile, &_tableEncode); - parseMaxpTable(_ttfile, &_numGlyphs); - parseHeadTable(_ttfile, _boundingBox, &(_glyphOffsets.format), &_unitsPerEm); + FILE* ttfile = fopen(_pathToFile,"rb"); + parseNameTable(ttfile, &_famName, &_psName, NULL); + parseCmapTable(ttfile, &_tableEncode); + parseMaxpTable(ttfile, &_numGlyphs); + parseHeadTable(ttfile, _boundingBox, &(_glyphOffsets.format), &_unitsPerEm); for (fint i=0; i<4; i++) _boundingBox[i]/=(ffloat)(_unitsPerEm); - parseLocaTable(_ttfile, &(_glyphOffsets), _numGlyphs); - parseHheaTable(_ttfile, &_numOfHMetrics, &_ascent, &_descent, &_externalLeading); + parseLocaTable(ttfile, &(_glyphOffsets), _numGlyphs); + parseHheaTable(ttfile, &_numOfHMetrics, &_ascent, &_descent, &_externalLeading); _ascent/=(ffloat)(_unitsPerEm); _descent = ((_descent>0)?_descent:(-_descent))/_unitsPerEm; _externalLeading/=(ffloat)(_unitsPerEm); - parseHmtxTable(_ttfile, _numOfHMetrics, &_hMetrics); - fclose(_ttfile); + parseHmtxTable(ttfile, _numOfHMetrics, &_hMetrics); + fclose(ttfile); } TTFont::~TTFont(void) @@ -60,15 +59,34 @@ Glyph* TTFont::createGlyph(ufshort unicode, ufshort size) { - TTGlyph *gl = new TTGlyph(this, unicode, size); - if (gl->_index < _numOfHMetrics) - gl->_advanceX = _hMetrics[gl->_index].adwance_width*(ffloat)(size)/(ffloat)(_unitsPerEm); - else - gl->_advanceX = _hMetrics[_numOfHMetrics-1].adwance_width*(ffloat)(size)/(ffloat)(_unitsPerEm); - gl->_advanceY = 0; - return gl; + return createGlyph(unicode, getGlyphIndex(unicode), size); } +TTGlyph* TTFont::createGlyph(ufshort unicode, ufshort index, ufshort size) +{ + TTGlyph* gl = new TTGlyph(this, unicode, index, size); + if (gl->_metrics < _numOfHMetrics) + gl->_advanceX = _hMetrics[gl->_metrics].adwance_width*(ffloat)(size)/(ffloat)(_unitsPerEm); + else + gl->_advanceX = _hMetrics[_numOfHMetrics-1].adwance_width*(ffloat)(size)/(ffloat)(_unitsPerEm); + gl->_advanceY = 0; + uflong id = (size << 16) + index; + _glyphIndexMap[(size << 16) + index] = gl; + return gl; +} + +TTGlyph* TTFont::getGlyphByIndex(ufshort index, ufshort size) +{ + uflong id = (size << 16) + index; + std::map::iterator iter = _glyphIndexMap.find(id); + if (iter != _glyphIndexMap.end()){ + return (TTGlyph *)(*iter).second; + } + TTGlyph* gl = createGlyph(getUnicodeByIndex(index), index, size); + registerGlyph(gl); + return gl; +} + ufshort TTFont::getGlyphIndex(ufshort symb) { ufshort index = 0; @@ -182,7 +200,7 @@ ffloat* TTFont::getLineMetrics() { //printf("reading file...\n"); - _ttfile = fopen(_pathToFile,"rb"); + FILE* ttfile = fopen(_pathToFile,"rb"); ffloat* ret = new ffloat[8]; ret[0] = _ascent; @@ -192,12 +210,12 @@ fshort uOffset, uThickness; //printf("parsing POST table...\n"); - parsePostTable(_ttfile, &uOffset, &uThickness); + parsePostTable(ttfile, &uOffset, &uThickness); ret[3] = (ffloat)uThickness/(ffloat)(_unitsPerEm); ret[4] = (ffloat)uOffset/(ffloat)(_unitsPerEm); //printf("parsing OS2 table...\n"); - parseOs2Table(_ttfile, &_strikeOutSize, &_strikeOutOffset); + parseOs2Table(ttfile, &_strikeOutSize, &_strikeOutOffset); ret[5] = _strikeOutSize; ret[6] = _strikeOutOffset; @@ -205,7 +223,7 @@ ffloat width = _boundingBox[3]-_boundingBox[1]; ret[7] = (width>0)?width:(-width); - fclose(_ttfile); + fclose(ttfile); return ret; } @@ -213,21 +231,15 @@ bool TTFont::canDisplay(ufshort c) { ufshort index = getGlyphIndex(c); -#ifdef WIN32 - bool isComposite = isCompositeGlyph(_ttfile, _glyphOffsets, _numGlyphs, index); - if (index == 0 || index >= _numGlyphs || isComposite) - return false; -#else if (index == 0 || index >= _numGlyphs) return false; -#endif return true; } /* *************** */ /* TTGlyph methods */ /* *************** */ -TTGlyph::TTGlyph(TTFont* font, ufshort unicode, ufshort size):Glyph() +TTGlyph::TTGlyph(TTFont* font, ufshort unicode, ufshort index, ufshort size):Glyph() { _ttfont = font; _unicode = unicode; @@ -237,11 +249,12 @@ _boundingRect[1]=0; _boundingRect[2]=0; _boundingRect[3]=0; + _index = index; + _metrics = index; - _ttfont->_ttfile = fopen(_ttfont->_pathToFile,"rb"); - _index = _ttfont->getGlyphIndex(_unicode); - parseGlyphData(_ttfont->_ttfile, _ttfont->_glyphOffsets,_ttfont->_numGlyphs,_index, _curve, _boundingRect, (ffloat)_size/(ffloat)(_ttfont->_unitsPerEm)); - fclose(_ttfont->_ttfile); + FILE* ttfile = fopen(_ttfont->_pathToFile,"rb"); + parseGlyphData(_ttfont, ttfile, _ttfont->_glyphOffsets,_ttfont->_numGlyphs,_index, _curve, _boundingRect, (ffloat)_size/(ffloat)(_ttfont->_unitsPerEm), size, &_metrics, _ttfont->_unitsPerEm); + fclose(ttfile); } TTGlyph::~TTGlyph() Index: classlib/modules/awt/src/main/native/fontlib/shared/Tables.h =================================================================== --- classlib/modules/awt/src/main/native/fontlib/shared/Tables.h (révision 949175) +++ classlib/modules/awt/src/main/native/fontlib/shared/Tables.h (copie de travail) @@ -70,6 +70,22 @@ Y_DWORD = 0x00, }; +enum +{ + ARG_1_AND_2_ARE_WORDS = 0x001, + ARGS_ARE_XY_VALUES = 0x002, + ROUND_XY_TO_GRID = 0x004, + + WE_HAVE_A_SCALE = 0x008, + WE_HAVE_AN_X_AND_Y_SCALE = 0x040, + WE_HAVE_A_TWO_BY_TWO = 0x080, + + MORE_COMPONENTS = 0x020, + WE_HAVE_INSTRUCTIONS = 0x100, + + USE_MY_METRICS = 0x200, +}; + /* From Win GDI typedef struct { ufchar bFamilyType; @@ -307,8 +323,7 @@ fint parseLocaTable(FILE* tt_file, GlyphOffsets* gOffsets, ufshort numGlyphs); fint parseOs2Table(FILE* tt_file, ffloat* strikeOutSize, ffloat* strikeOutOffset); fint parsePostTable(FILE* tt_file, fshort* uOffset, fshort* uThickness); -fint parseGlyphData(FILE* tt_file, const GlyphOffsets gO, ufshort numGlyphs, ufshort glyphIndex, TTCurve *curve, fshort* bRect, ffloat transform); +fint parseGlyphData(TTFont *tt_font, FILE* tt_file, const GlyphOffsets gO, ufshort numGlyphs, ufshort glyphIndex, TTCurve *curve, fshort* bRect, ffloat transform, ufshort size, ufshort *metricsIndex, ufshort unitsPerEm); fint parseHmtxTable(FILE* tt_file, ufshort numOfHMetrics, HMetrics** hm); -bool isCompositeGlyph(FILE* tt_file, const GlyphOffsets gO, ufshort numGlyphs, ufshort glyphIndex); #endif Index: classlib/modules/awt/src/main/native/fontlib/shared/TTFont.h =================================================================== --- classlib/modules/awt/src/main/native/fontlib/shared/TTFont.h (révision 949175) +++ classlib/modules/awt/src/main/native/fontlib/shared/TTFont.h (copie de travail) @@ -20,6 +20,7 @@ #ifndef __TTFONT_H__ #define __TTFONT_H__ +#include #include "Font.h" #include "Glyph.h" #include "Outline.h" @@ -57,38 +58,43 @@ ufshort _unitsPerEm; //size of em-square ufshort _numOfHMetrics; // for 'hmtx' table HMetrics* _hMetrics; // horizontal metrics for all glyphs - FILE* _ttfile; ufshort getGlyphIndex(ufshort symb); ufshort getUnicodeByIndex(ufshort ind); // friend ufshort TTGlyph::getGlyphIndex(ufshort symb); // friend fint TTGlyph::initialize(); + TTGlyph* createGlyph(ufshort unicode, ufshort index, ufshort size); + + std::map _glyphIndexMap; + public: TTFont(fchar* pathToFile); ~TTFont(void); - + Glyph* createGlyph(ufshort unicode, ufshort size); fwchar_t* getPSName(); ffloat* getLineMetrics(); bool canDisplay(ufshort c); + TTGlyph* getGlyphByIndex(ufshort index, ufshort size); // ffloat* GetExtraMetrics(); }; - class TTGlyph : public Glyph { private: TTFont* _ttfont; - ufshort _index; + ufshort _index; + ufshort _metrics; TTCurve* _curve; fshort _boundingRect[4]; - friend Glyph* TTFont::createGlyph(ufshort unicode, ufshort size); + friend TTGlyph* TTFont::createGlyph(ufshort unicode, ufshort index, ufshort size); + friend fint parseCompositeGlyphData(TTFont*, FILE*, TTCurve*, ffloat, ufshort, ufshort*, ufshort); public: - TTGlyph(TTFont *font, ufshort unicode, ufshort size); + TTGlyph(TTFont *font, ufshort unicode, ufshort index, ufshort size); ~TTGlyph(); Outline* getOutline(void); ffloat* getGlyphMetrics(void); Index: classlib/modules/awt/src/main/native/fontlib/shared/TTCurve.cpp =================================================================== --- classlib/modules/awt/src/main/native/fontlib/shared/TTCurve.cpp (révision 949175) +++ classlib/modules/awt/src/main/native/fontlib/shared/TTCurve.cpp (copie de travail) @@ -19,7 +19,7 @@ */ #include "TTCurve.h" #include "memory.h" - +#include TTCurve::TTCurve() { _len = 0; @@ -60,3 +60,38 @@ delete[] tmpF; return 0; } + +fint TTCurve::merge(TTCurve* curve, ffloat xOffset, ffloat yOffset, ffloat xScale, ffloat yScale, ffloat scale01, ffloat scale10) +{ + fint oldLen = _len; + _len += curve->_len; + _outlineCommandsNumb += curve->_outlineCommandsNumb - 1; + + ffloat* tmpC = _coords; + ufchar* tmpF = _flags; + + _coords = new ffloat[_len]; + _flags = new ufchar[(_len+1)/2]; + memcpy(_coords,tmpC,oldLen*sizeof(ffloat)); + if (xOffset == 0 && yOffset == 0 && xScale == 1 && yScale == 1 && scale01 == 0 && scale10 == 0) + { + memcpy(_coords+oldLen,curve->_coords,curve->_len*sizeof(ffloat)); + }else + { + ffloat x, y; + for (int i = 0 ; i < curve->_len ; i+=2) + { + x = curve->_coords[i]; + y = curve->_coords[i+1]; + _coords[oldLen+i] = xScale * x + scale10 * y + xOffset; + _coords[oldLen+i+1] = yScale * y + scale01 * x + yOffset; + } + } + + memcpy(_flags,tmpF,(oldLen+1)/2); + memcpy(_flags+(oldLen+1)/2,curve->_flags,((curve->_len+1)/2)*sizeof(fchar)); + + delete[] tmpC; + delete[] tmpF; + return 0; +}