- }
-
- msg("<verbose> \"%s\" link to \"%s\" (%d)\n", type, FIXNULL(s), page);
- free(s);s=0;
-}
-
-void GFXOutputDev::saveState(GfxState *state) {
- msg("<trace> saveState\n");
- updateAll(state);
- if(statepos>=64) {
- msg("<error> Too many nested states in pdf.");
- return;
- }
- statepos ++;
- states[statepos].textRender = states[statepos-1].textRender;
- states[statepos].createsoftmask = states[statepos-1].createsoftmask;
- states[statepos].transparencygroup = states[statepos-1].transparencygroup;
- states[statepos].clipping = 0;
-};
-
-void GFXOutputDev::restoreState(GfxState *state) {
- if(statepos==0) {
- msg("<error> Invalid restoreState");
- return;
- }
- msg("<trace> restoreState");
- updateAll(state);
- while(states[statepos].clipping) {
- device->endclip(device);
- states[statepos].clipping--;
- }
- statepos--;
-}
-
-char* GFXOutputDev::searchFont(char*name)
-{
- int i;
- char*filename=0;
- int is_standard_font = 0;
-
- msg("<verbose> SearchFont(%s)", name);
-
- /* see if it is a pdf standard font */
- for(i=0;i<sizeof(pdf2t1map)/sizeof(mapping);i++)
- {
- if(!strcmp(name, pdf2t1map[i].pdffont))
- {
- name = pdf2t1map[i].filename;
- is_standard_font = 1;
- break;
- }
- }
- /* look in all font files */
- for(i=0;i<fontnum;i++)
- {
- if(strstr(fonts[i].filename, name))
- {
- if(!fonts[i].used) {
-
- fonts[i].used = 1;
- if(!is_standard_font)
- msg("<notice> Using %s for %s", fonts[i].filename, name);
- }
- return strdup(fonts[i].filename);
- }
- }
- return 0;
-}
-
-void GFXOutputDev::updateLineWidth(GfxState *state)
-{
- double width = state->getTransformedLineWidth();
- //swfoutput_setlinewidth(&device, width);
-}
-
-void GFXOutputDev::updateLineCap(GfxState *state)
-{
- int c = state->getLineCap();
-}
-
-void GFXOutputDev::updateLineJoin(GfxState *state)
-{
- int j = state->getLineJoin();
-}
-
-void GFXOutputDev::updateFillColor(GfxState *state)
-{
- GfxRGB rgb;
- double opaq = state->getFillOpacity();
- state->getFillRGB(&rgb);
-}
-void GFXOutputDev::updateFillOpacity(GfxState *state)
-{
- GfxRGB rgb;
- double opaq = state->getFillOpacity();
- state->getFillRGB(&rgb);
-}
-
-void GFXOutputDev::updateStrokeColor(GfxState *state)
-{
- GfxRGB rgb;
- double opaq = state->getStrokeOpacity();
- state->getStrokeRGB(&rgb);
-}
-
-void FoFiWrite(void *stream, char *data, int len)
-{
- int ret = fwrite(data, len, 1, (FILE*)stream);
-}
-
-char*GFXOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
-{
- char*tmpFileName = NULL;
- FILE *f;
- int c;
- char *fontBuf;
- int fontLen;
- Ref embRef;
- Object refObj, strObj;
- char namebuf[512];
- tmpFileName = mktmpname(namebuf);
- int ret;
-
- ret = font->getEmbeddedFontID(&embRef);
- if(!ret) {
- msg("<verbose> Didn't get embedded font id");
- /* not embedded- the caller should now search the font
- directories for this font */
- return 0;
- }
-
- f = fopen(tmpFileName, "wb");
- if (!f) {
- msg("<error> Couldn't create temporary Type 1 font file");
- return 0;
- }
-
- /*if(font->isCIDFont()) {
- GfxCIDFont* cidFont = (GfxCIDFont *)font;
- GString c = cidFont->getCollection();
- msg("<notice> Collection: %s", c.getCString());
- }*/
-
- //if (font->getType() == fontType1C) {
- if (0) { //font->getType() == fontType1C) {
- if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
- fclose(f);
- msg("<error> Couldn't read embedded font file");
- return 0;
- }
- FoFiType1C *cvt = FoFiType1C::make(fontBuf, fontLen);
- if(!cvt) return 0;
- cvt->convertToType1(NULL, gTrue, FoFiWrite, f);
- //cvt->convertToCIDType0("test", f);
- //cvt->convertToType0("test", f);
- delete cvt;
- gfree(fontBuf);
- } else if(font->getType() == fontTrueType) {
- msg("<verbose> writing font using TrueTypeFontFile::writeTTF");
- if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
- fclose(f);
- msg("<error> Couldn't read embedded font file");
- return 0;
- }
- FoFiTrueType *cvt = FoFiTrueType::make(fontBuf, fontLen);
- cvt->writeTTF(FoFiWrite, f);
- delete cvt;
- gfree(fontBuf);
- } else {
- font->getEmbeddedFontID(&embRef);
- refObj.initRef(embRef.num, embRef.gen);
- refObj.fetch(ref, &strObj);
- refObj.free();
- strObj.streamReset();
- int f4[4];
- char f4c[4];
- int t;
- for(t=0;t<4;t++) {
- f4[t] = strObj.streamGetChar();
- f4c[t] = (char)f4[t];
- if(f4[t] == EOF)
- break;
- }
- if(t==4) {
- if(!strncmp(f4c, "true", 4)) {
- /* some weird TTF fonts don't start with 0,1,0,0 but with "true".
- Change this on the fly */
- f4[0] = f4[2] = f4[3] = 0;
- f4[1] = 1;
- }
- fputc(f4[0], f);
- fputc(f4[1], f);
- fputc(f4[2], f);
- fputc(f4[3], f);
-
- while ((c = strObj.streamGetChar()) != EOF) {
- fputc(c, f);
- }
- }
- strObj.streamClose();
- strObj.free();
- }
- fclose(f);
-
- return strdup(tmpFileName);
-}
-
-char* GFXOutputDev::searchForSuitableFont(GfxFont*gfxFont)
-{
- char*name = getFontName(gfxFont);
- char*fontname = 0;
- char*filename = 0;
-
- 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);