"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Plugins/Pdf/PDFWriter/FreeTypeFaceWrapper.cpp" between
TeXmacs-1.99.4-src.tar.gz and TeXmacs-1.99.5-src.tar.gz

About: GNU TeXmacs is a what-you-see-is-what-you-get scientific text editor, which was both inspired by TeX and GNU Emacs.

FreeTypeFaceWrapper.cpp  (TeXmacs-1.99.4-src):FreeTypeFaceWrapper.cpp  (TeXmacs-1.99.5-src)
skipping to change at line 28 skipping to change at line 28
*/ */
#include "FreeTypeFaceWrapper.h" #include "FreeTypeFaceWrapper.h"
#include "IFreeTypeFaceExtender.h" #include "IFreeTypeFaceExtender.h"
#include "FreeTypeType1Wrapper.h" #include "FreeTypeType1Wrapper.h"
#include "FreeTypeOpenTypeWrapper.h" #include "FreeTypeOpenTypeWrapper.h"
#include "Trace.h" #include "Trace.h"
#include "BetweenIncluding.h" #include "BetweenIncluding.h"
#include "WrittenFontCFF.h" #include "WrittenFontCFF.h"
#include "WrittenFontTrueType.h" #include "WrittenFontTrueType.h"
#include <math.h>
#include FT_XFREE86_H #include FT_XFREE86_H
#include FT_CID_H #include FT_CID_H
#include FT_OUTLINE_H
using namespace PDFHummus; using namespace PDFHummus;
FreeTypeFaceWrapper::FreeTypeFaceWrapper(FT_Face inFace,const std::string& inFon tFilePath,long inFontIndex,bool inDoOwn) FreeTypeFaceWrapper::FreeTypeFaceWrapper(FT_Face inFace,const std::string& inFon tFilePath,long inFontIndex,bool inDoOwn)
{ {
mFace = inFace; mFace = inFace;
mFontFilePath = inFontFilePath; mFontFilePath = inFontFilePath;
mFontIndex = inFontIndex; mFontIndex = inFontIndex;
SetupFormatSpecificExtender(inFontFilePath,""); SetupFormatSpecificExtender(inFontFilePath,"");
mDoesOwn = inDoOwn; mDoesOwn = inDoOwn;
SetupNotDefGlyph(); mGlyphIsLoaded = false;
} }
FreeTypeFaceWrapper::FreeTypeFaceWrapper(FT_Face inFace,const std::string& inFon tFilePath,const std::string& inPFMFilePath,long inFontIndex, bool inDoOwn) FreeTypeFaceWrapper::FreeTypeFaceWrapper(FT_Face inFace,const std::string& inFon tFilePath,const std::string& inPFMFilePath,long inFontIndex, bool inDoOwn)
{ {
mFace = inFace; mFace = inFace;
mFontFilePath = inFontFilePath; mFontFilePath = inFontFilePath;
mFontIndex = inFontIndex; mFontIndex = inFontIndex;
std::string fileExtension = GetExtension(inPFMFilePath); std::string fileExtension = GetExtension(inPFMFilePath);
if(fileExtension == "PFM" || fileExtension == "pfm") // just don't bothe r if it's not PFM if(fileExtension == "PFM" || fileExtension == "pfm") // just don't bothe r if it's not PFM
SetupFormatSpecificExtender(inFontFilePath,inPFMFilePath); SetupFormatSpecificExtender(inFontFilePath,inPFMFilePath);
else else
SetupFormatSpecificExtender(inFontFilePath,""); SetupFormatSpecificExtender(inFontFilePath,"");
mDoesOwn = inDoOwn; mDoesOwn = inDoOwn;
SetupNotDefGlyph(); mGlyphIsLoaded = false;
} }
void FreeTypeFaceWrapper::SetupNotDefGlyph() std::string FreeTypeFaceWrapper::NotDefGlyphName()
{ {
// for special case of fonts that have glyph names, but don't define .notdef , use one of the existing chars (found a custom type 1 with that) // for special case of fonts that have glyph names, but don't define .notdef , use one of the existing chars (found a custom type 1 with that)
if(FT_HAS_GLYPH_NAMES(mFace)) if (mNotDefGlyphName.length() == 0) {
{ if(FT_HAS_GLYPH_NAMES(mFace))
char* aString = (char*)".notdef"; {
if(FT_Get_Name_Index(mFace,aString) == 0) { char* aString = (char*)".notdef";
FT_UInt gindex; if(FT_Get_Name_Index(mFace,aString) == 0) {
FT_Get_First_Char( mFace, &gindex ); FT_UInt gindex;
mNotDefGlyphName = GetGlyphName(gindex); FT_Get_First_Char( mFace, &gindex );
// WARNING: it can happen that (mNotDefGlyphName == "") if (gindex != 0)
} mNotDefGlyphName = GetGlyphName(gindex, true);
else }
mNotDefGlyphName = ".notdef"; }
} if (mNotDefGlyphName == "") mNotDefGlyphName = ".notdef";
}
if (mNotDefGlyphName == "") mNotDefGlyphName = ".notdef"; return mNotDefGlyphName;
} }
std::string FreeTypeFaceWrapper::GetExtension(const std::string& inFilePath) std::string FreeTypeFaceWrapper::GetExtension(const std::string& inFilePath)
{ {
std::string::size_type dotPosition = inFilePath.rfind("."); std::string::size_type dotPosition = inFilePath.rfind(".");
if(inFilePath.npos == dotPosition || (inFilePath.size() - 1) == dotPositi on) if(inFilePath.npos == dotPosition || (inFilePath.size() - 1) == dotPositi on)
return ""; return "";
else else
return inFilePath.substr(dotPosition + 1); return inFilePath.substr(dotPosition + 1);
skipping to change at line 229 skipping to change at line 232
BoolAndFTShort FreeTypeFaceWrapper::XHeightFromLowerXHeight() BoolAndFTShort FreeTypeFaceWrapper::XHeightFromLowerXHeight()
{ {
// calculate based on Y bearing of the lower x // calculate based on Y bearing of the lower x
return GetYBearingForUnicodeChar(0x78); return GetYBearingForUnicodeChar(0x78);
} }
BoolAndFTShort FreeTypeFaceWrapper::GetYBearingForUnicodeChar(unsigned short uni codeCharCode) BoolAndFTShort FreeTypeFaceWrapper::GetYBearingForUnicodeChar(unsigned short uni codeCharCode)
{ {
if(mFace) if(mFace)
{ {
if(FT_Load_Char(mFace,unicodeCharCode, FT_LOAD_NO_SCALE) != 0) mGlyphIsLoaded = false;
if (FT_Load_Char(mFace, unicodeCharCode, FT_LOAD_NO_HINTING | FT_
LOAD_NO_AUTOHINT | FT_LOAD_NO_SCALE) != 0)
{ {
TRACE_LOG1("FreeTypeFaceWrapper::XHeightFromLowerXHeight, unable to load glyph for char code = 0x%x",unicodeCharCode); TRACE_LOG1("FreeTypeFaceWrapper::XHeightFromLowerXHeight, unable to load glyph for char code = 0x%x",unicodeCharCode);
return BoolAndFTShort(false,0); return BoolAndFTShort(false,0);
} }
return BoolAndFTShort(true,(FT_Short)mFace->glyph->metrics.horiBe aringY); return BoolAndFTShort(true,(FT_Short)mFace->glyph->metrics.horiBe aringY);
} }
else else
return BoolAndFTShort(false,0); return BoolAndFTShort(false,0);
} }
skipping to change at line 512 skipping to change at line 516
bool FreeTypeFaceWrapper::IsItalic() bool FreeTypeFaceWrapper::IsItalic()
{ {
return GetItalicAngle() != 0; return GetItalicAngle() != 0;
} }
bool FreeTypeFaceWrapper::IsForceBold() bool FreeTypeFaceWrapper::IsForceBold()
{ {
return mFormatParticularWrapper ? mFormatParticularWrapper->IsForceBold() : false; return mFormatParticularWrapper ? mFormatParticularWrapper->IsForceBold() : false;
} }
std::string FreeTypeFaceWrapper::GetGlyphName(unsigned int inGlyphIndex) std::string FreeTypeFaceWrapper::GetPostscriptName()
{
std::string name;
const char* postscriptFontName = FT_Get_Postscript_Name(mFace);
if(postscriptFontName)
{
name.assign(postscriptFontName);
}
else
{
// some fonts have the postscript name data, but in a non standar
d way, try to retrieve
if(mFormatParticularWrapper)
name = mFormatParticularWrapper->GetPostscriptNameNonStan
dard();
if(name.length() == 0)
TRACE_LOG("FreeTypeFaceWrapper::GetPostscriptName, unexpe
cted failure. no postscript font name for font");
}
return name;
}
std::string FreeTypeFaceWrapper::GetGlyphName(unsigned int inGlyphIndex, bool sa
fe)
{ {
if(mFormatParticularWrapper && mFormatParticularWrapper->HasPrivateEncoding( )) if(mFormatParticularWrapper && mFormatParticularWrapper->HasPrivateEncoding( ))
{ {
std::string glyphName = mFormatParticularWrapper->GetPrivateGlyphName(in GlyphIndex); std::string glyphName = mFormatParticularWrapper->GetPrivateGlyphName(in GlyphIndex);
if(glyphName == ".notdef") if(glyphName == ".notdef" && !safe)
return mNotDefGlyphName; // handling fonts that don't have notdef return NotDefGlyphName(); // handling fonts that don't have notdef
else else
return glyphName; return glyphName;
} }
else else
{ {
if(inGlyphIndex < (unsigned int)mFace->num_glyphs) if(inGlyphIndex < (unsigned int)mFace->num_glyphs)
{ {
char buffer[100]; char buffer[100];
FT_Get_Glyph_Name(mFace,inGlyphIndex,buffer,100); FT_Get_Glyph_Name(mFace,inGlyphIndex,buffer,100);
return std::string(buffer); return std::string(buffer);
} }
else else
return mNotDefGlyphName; // normally this will be .notdef (in am all owing edge/illegal cases where there's a font with no .notdef) return NotDefGlyphName(); // normally this will be .notdef (in am al lowing edge/illegal cases where there's a font with no .notdef)
} }
} }
EStatusCode FreeTypeFaceWrapper::GetGlyphsForUnicodeText(const ULongList& inUnic odeCharacters,UIntList& outGlyphs) EStatusCode FreeTypeFaceWrapper::GetGlyphsForUnicodeText(const ULongList& inUnic odeCharacters,UIntList& outGlyphs)
{ {
if(mFace) if(mFace)
{ {
FT_UInt glyphIndex; FT_UInt glyphIndex;
EStatusCode status = PDFHummus::eSuccess; EStatusCode status = PDFHummus::eSuccess;
skipping to change at line 669 skipping to change at line 694
return inFontMeasurement; return inFontMeasurement;
else else
return FT_Pos((double)inFontMeasurement * 1000.0 / mFace- >units_per_EM); return FT_Pos((double)inFontMeasurement * 1000.0 / mFace- >units_per_EM);
} }
else else
return 0; return 0;
} }
FT_Pos FreeTypeFaceWrapper::GetGlyphWidth(unsigned int inGlyphIndex) FT_Pos FreeTypeFaceWrapper::GetGlyphWidth(unsigned int inGlyphIndex)
{ {
if(mFormatParticularWrapper && mFormatParticularWrapper->HasPrivateEncoding( if (LoadGlyph(inGlyphIndex))
)) return 0;
FT_Load_Glyph(mFace,mFormatParticularWrapper->GetFreeTypeGlyphIndexFromE else
ncodingGlyphIndex(inGlyphIndex),FT_LOAD_NO_SCALE); return GetInPDFMeasurements(mFace->glyph->metrics.horiAdvance);
else
FT_Load_Glyph(mFace,inGlyphIndex,FT_LOAD_NO_SCALE);
return GetInPDFMeasurements(mFace->glyph->metrics.horiAdvance);
} }
unsigned int FreeTypeFaceWrapper::GetGlyphIndexInFreeTypeIndexes(unsigned int in GlyphIndex) unsigned int FreeTypeFaceWrapper::GetGlyphIndexInFreeTypeIndexes(unsigned int in GlyphIndex)
{ {
if(mFormatParticularWrapper && mFormatParticularWrapper->HasPrivateEncoding( )) if(mFormatParticularWrapper && mFormatParticularWrapper->HasPrivateEncoding( ))
return mFormatParticularWrapper->GetFreeTypeGlyphIndexFromEncodingGlyphI ndex(inGlyphIndex); return mFormatParticularWrapper->GetFreeTypeGlyphIndexFromEncodingGlyphI ndex(inGlyphIndex);
else else
return inGlyphIndex; return inGlyphIndex;
}
bool FreeTypeFaceWrapper::GetGlyphOutline(unsigned int inGlyphIndex, FreeTypeFac
eWrapper::IOutlineEnumerator& inEnumerator)
{
bool status = false;
if ( mFace->glyph->format == FT_GLYPH_FORMAT_OUTLINE && !(mFace->face_fla
gs & FT_FACE_FLAG_TRICKY) ) //scaled-font implementation would be needed for 'tr
icky' fonts
{
if (!LoadGlyph(inGlyphIndex)) {
FT_Outline_Funcs callbacks = { IOutlineEnumerator::outlin
e_moveto,
IOutlineEnumerator::outlin
e_lineto,
IOutlineEnumerator::outline_conicto,
IOutlineEnumerator::outline_cubicto,
0, 0 }; //0 shift & delta
inEnumerator.FTBegin(mFace->units_per_EM);
status = ( 0 == FT_Outline_Decompose(&mFace->glyph->outli
ne, &callbacks, &inEnumerator) );
inEnumerator.FTEnd();
status = true;
}
}
return status;
}
FT_Error FreeTypeFaceWrapper::LoadGlyph(FT_UInt inGlyphIndex, FT_Int32 inFlags)
{
FT_Error status = 0; //assume success
if (!mGlyphIsLoaded || inGlyphIndex != mCurrentGlyph) {
if (mFormatParticularWrapper && mFormatParticularWrapper->HasPriv
ateEncoding())
status = FT_Load_Glyph(mFace,
mFormatParticularWrapper->GetFreeT
ypeGlyphIndexFromEncodingGlyphIndex(inGlyphIndex),
inFlags | FT_L
OAD_NO_HINTING | FT_LOAD_NO_AUTOHINT | FT_LOAD_NO_SCALE);
else
status = FT_Load_Glyph(mFace,inGlyphIndex, inFlags | FT_L
OAD_NO_HINTING | FT_LOAD_NO_AUTOHINT | FT_LOAD_NO_SCALE);
mGlyphIsLoaded = true;
mCurrentGlyph = inGlyphIndex;
}
return status;
}
//////////////// IOutlineEnumerator /////////////////////////////
int FreeTypeFaceWrapper::IOutlineEnumerator::outline_moveto(const FT_Vector* to,
void *closure) //static
{
return ( (FreeTypeFaceWrapper::IOutlineEnumerator *)closure )->FTMoveto(t
o) ? 0 : 1;
}
int FreeTypeFaceWrapper::IOutlineEnumerator::outline_lineto(const FT_Vector* to,
void *closure) //static
{
return ( (FreeTypeFaceWrapper::IOutlineEnumerator *)closure )->FTLineto(t
o) ? 0 : 1;
}
int FreeTypeFaceWrapper::IOutlineEnumerator::outline_conicto(const FT_Vector *co
ntrol, const FT_Vector *to, void *closure) //static
{
return ( (FreeTypeFaceWrapper::IOutlineEnumerator *)closure )->FTConicto(
control, to) ? 0 : 1;
}
int FreeTypeFaceWrapper::IOutlineEnumerator::outline_cubicto(const FT_Vector *co
ntrol1, const FT_Vector *control2, const FT_Vector *to, void *closure) //static
{
return ( (FreeTypeFaceWrapper::IOutlineEnumerator *)closure )->FTCubicto(
control1, control2, to) ? 0 : 1;
}
void FreeTypeFaceWrapper::IOutlineEnumerator::FTBegin(FT_UShort upm)
{
mUPM = upm;
mToLastValid = false;
}
bool FreeTypeFaceWrapper::IOutlineEnumerator::FTMoveto(const FT_Vector* to)
{
bool stat = true;
if (mToLastValid)
stat = Close(); //some font types skip doing closepaths
if (stat)
stat = Moveto( FT_Short(to->x), FT_Short(to->y) ); //OK to trunca
te FT_Pos when fonts are unscaled
mToLast = *to;
mToLastValid = true;
return stat;
}
bool FreeTypeFaceWrapper::IOutlineEnumerator::FTLineto(const FT_Vector* to)
{
mToLast = *to;
mToLastValid = true;
return Lineto( FT_Short(to->x), FT_Short(to->y) );
}
static inline FT_Pos ftround(double x)
{
return FT_Pos(x >= 0 ? floor(x + 0.5) : ceil(x - .5));
}
bool FreeTypeFaceWrapper::IOutlineEnumerator::FTConicto(const FT_Vector *control
, const FT_Vector *to)
{
FT_Vector from = mToLast;
mToLast = *to;
return Curveto( FT_Short(from.x + ftround(2.0/3.0 * (control->x - from.x)
)),
FT_Short(from.y + ftround(2.0/3.0 * (control->y - from.y)
)),
FT_Short(to->x + ftround(2.0/3.0 * (control->x - to->x)))
,
FT_Short(to->y + ftround(2.0/3.0 * (control->y - to->y)))
,
FT_Short(to->x),
FT_Short(to->y) );
}
bool FreeTypeFaceWrapper::IOutlineEnumerator::FTCubicto(const FT_Vector *control
1, const FT_Vector *control2, const FT_Vector *to)
{
mToLast = *to;
return Curveto( FT_Short(control1->x), FT_Short(control1->y),
FT_Short(control2->x), FT_Short(control2->y),
FT_Short(to->x), FT_Short(to->y) );
}
void FreeTypeFaceWrapper::IOutlineEnumerator::FTEnd()
{
if (mToLastValid)
Close();
mToLastValid = false;
} }
 End of changes. 13 change blocks. 
29 lines changed or deleted 199 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS