- if(!this->config_use_fontconfig)
- return 0;
-
-#ifdef HAVE_FONTCONFIG
- FcPattern *pattern, *match;
- FcResult result;
- FcChar8 *v;
-
- static int fcinitcalled = false;
-
- msg("<debug> searchForSuitableFont(%s)", name);
-
- // call init ony once
- if (!fcinitcalled) {
- msg("<debug> Initializing FontConfig...");
- fcinitcalled = true;
- if(!FcInit()) {
- msg("<debug> FontConfig Initialization failed. Disabling.");
- config_use_fontconfig = 0;
- return 0;
- }
- msg("<debug> ...initialized FontConfig");
- }
-
- msg("<debug> FontConfig: Create \"%s\" Family Pattern", name);
- pattern = FcPatternBuild(NULL, FC_FAMILY, FcTypeString, name, NULL);
- if (gfxFont->isItalic()) // check for italic
- msg("<debug> FontConfig: Adding Italic Slant");
- FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
- if (gfxFont->isBold()) // check for bold
- msg("<debug> FontConfig: Adding Bold Weight");
- FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
-
- msg("<debug> FontConfig: Try to match...");
- // configure and match using the original font name
- FcConfigSubstitute(0, pattern, FcMatchPattern);
- FcDefaultSubstitute(pattern);
- match = FcFontMatch(0, pattern, &result);
-
- if (FcPatternGetString(match, "family", 0, &v) == FcResultMatch) {
- msg("<debug> FontConfig: family=%s", (char*)v);
- // if we get an exact match
- if (strcmp((char *)v, name) == 0) {
- if (FcPatternGetString(match, "file", 0, &v) == FcResultMatch) {
- filename = strdup((char*)v); // mem leak
- char *nfn = strrchr(filename, '/');
- if(nfn) fontname = strdup(nfn+1);
- else fontname = filename;
- }
- msg("<debug> FontConfig: Returning \"%s\"", fontname);
- } else {
- // initialize patterns
- FcPatternDestroy(pattern);
- FcPatternDestroy(match);
-
- // now match against serif etc.
- if (gfxFont->isSerif()) {
- msg("<debug> FontConfig: Create Serif Family Pattern");
- pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "serif", NULL);
- } else if (gfxFont->isFixedWidth()) {
- msg("<debug> FontConfig: Create Monospace Family Pattern");
- pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "monospace", NULL);
- } else {
- msg("<debug> FontConfig: Create Sans Family Pattern");
- pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "sans", NULL);
- }
-
- // check for italic
- if (gfxFont->isItalic()) {
- msg("<debug> FontConfig: Adding Italic Slant");
- int bb = FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
- }
- // check for bold
- if (gfxFont->isBold()) {
- msg("<debug> FontConfig: Adding Bold Weight");
- int bb = FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
- }
-
- msg("<debug> FontConfig: Try to match... (2)");
- // configure and match using serif etc
- FcConfigSubstitute (0, pattern, FcMatchPattern);
- FcDefaultSubstitute (pattern);
- match = FcFontMatch (0, pattern, &result);
-
- if (FcPatternGetString(match, "file", 0, &v) == FcResultMatch) {
- filename = strdup((char*)v); // mem leak
- char *nfn = strrchr(filename, '/');
- if(nfn) fontname = strdup(nfn+1);
- else fontname = filename;
- }
- msg("<debug> FontConfig: Returning \"%s\"", fontname);
- }
- }
-
- //printf("FONTCONFIG: pattern");
- //FcPatternPrint(pattern);
- //printf("FONTCONFIG: match");
- //FcPatternPrint(match);
-
- FcPatternDestroy(pattern);
- FcPatternDestroy(match);
-
- pdfswf_addfont(filename);
- return fontname;
-#else
- return 0;
-#endif
-}
-
-char* GFXOutputDev::substituteFont(GfxFont*gfxFont, char* oldname)
-{
- const char*fontname = 0, *filename = 0;
- msg("<notice> substituteFont(%s)", oldname);
-
- if(!(fontname = searchForSuitableFont(gfxFont))) {
- fontname = "Times-Roman";
- }
- filename = searchFont(fontname);
- if(!filename) {
- msg("<error> Couldn't find font %s- did you install the default fonts?", fontname);
- return 0;
- }
-
- if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
- msg("<fatal> Too many fonts in file.");
- exit(1);
- }
- if(oldname) {
- substitutesource[substitutepos] = strdup(oldname); //mem leak
- substitutetarget[substitutepos] = fontname;
- msg("<notice> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
- substitutepos ++;
- }
- return strdup(filename); //mem leak
-}
-
-void unlinkfont(char* filename)
-{
- int l;
- if(!filename)
- return;
- l=strlen(filename);
- unlink(filename);
- if(!strncmp(&filename[l-4],".afm",4)) {
- memcpy(&filename[l-4],".pfb",4);
- unlink(filename);
- memcpy(&filename[l-4],".pfa",4);
- unlink(filename);
- memcpy(&filename[l-4],".afm",4);
- return;
- } else
- if(!strncmp(&filename[l-4],".pfa",4)) {
- memcpy(&filename[l-4],".afm",4);
- unlink(filename);
- memcpy(&filename[l-4],".pfa",4);
- return;
- } else
- if(!strncmp(&filename[l-4],".pfb",4)) {
- memcpy(&filename[l-4],".afm",4);
- unlink(filename);
- memcpy(&filename[l-4],".pfb",4);
- return;
- }
-}
-
-void GFXOutputDev::setXRef(PDFDoc*doc, XRef *xref)
-{
- this->doc = doc;
- this->xref = xref;
-}
-
-int GFXOutputDev::setGfxFont(char*id, char*name, char*filename, double maxSize, CharCodeToUnicode*ctu)
-{
- gfxfont_t*font = 0;
- fontlist_t*last=0,*l = this->fontlist;
-
- if(!id)
- msg("<error> Internal Error: FontID is null");
-
- /* TODO: should this be part of the state? */
- while(l) {
- last = l;
- if(!strcmp(l->font->id, id)) {
- current_gfxfont = l->font;
- font = l->font;
- device->addfont(device, current_gfxfont);
- return 1;
+ font->glyphs = (gfxglyph_t*)malloc(sizeof(gfxglyph_t)*src->num_glyphs);
+ memset(font->glyphs, 0, sizeof(gfxglyph_t)*src->num_glyphs);
+ font->id = strdup(getFontID(xpdffont));
+ int t;
+ double quality = (INTERNAL_FONT_SIZE * 0.05) / src->max_size;
+ double scale = 1;
+ //printf("%d glyphs\n", font->num_glyphs);
+ font->num_glyphs = 0;
+ for(t=0;t<src->num_glyphs;t++) {
+ if(src->glyphs[t]) {
+ SplashPath*path = src->glyphs[t]->path;
+ int len = path?path->getLength():0;
+ //printf("glyph %d) %08x (%d line segments)\n", t, path, len);
+ gfxglyph_t*glyph = &font->glyphs[font->num_glyphs];
+ src->glyphs[t]->glyphid = font->num_glyphs;
+ glyph->unicode = src->glyphs[t]->unicode;
+ if(glyph->unicode >= font->max_unicode)
+ font->max_unicode = glyph->unicode+1;
+ gfxdrawer_t drawer;
+ gfxdrawer_target_gfxline(&drawer);
+ int s;
+ int count = 0;
+ double xmax = 0;
+ for(s=0;s<len;s++) {
+ Guchar f;
+ double x, y;
+ path->getPoint(s, &x, &y, &f);
+ if(!s || x > xmax)
+ xmax = x;
+ if(f&splashPathFirst) {
+ drawer.moveTo(&drawer, x*scale, y*scale);
+ }
+ if(f&splashPathCurve) {
+ double x2,y2;
+ path->getPoint(++s, &x2, &y2, &f);
+ if(f&splashPathCurve) {
+ double x3,y3;
+ path->getPoint(++s, &x3, &y3, &f);
+ gfxdraw_cubicTo(&drawer, x*scale, y*scale, x2*scale, y2*scale, x3*scale, y3*scale, quality);
+ } else {
+ drawer.splineTo(&drawer, x*scale, y*scale, x2*scale, y2*scale);
+ }
+ } else {
+ drawer.lineTo(&drawer, x*scale, y*scale);
+ }
+ // printf("%f %f %s %s\n", x, y, (f&splashPathCurve)?"curve":"",
+ // (f&splashPathFirst)?"first":"",
+ // (f&splashPathLast)?"last":"");
+ }
+ glyph->line = (gfxline_t*)drawer.result(&drawer);
+ glyph->advance = xmax*scale; // we don't know the real advance value, so this'll have to do
+ font->num_glyphs++;