From a972dbb9bd731a439d009bd51e36981c41a06232 Mon Sep 17 00:00:00 2001 From: scuri Date: Tue, 20 Oct 2009 18:12:26 +0000 Subject: *** empty log message *** --- src/pdflib/font/ft_cid.c | 26 ++-- src/pdflib/font/ft_cid.h | 2 +- src/pdflib/font/ft_corefont.c | 2 +- src/pdflib/font/ft_corefont.h | 5 +- src/pdflib/font/ft_font.c | 52 +++++--- src/pdflib/font/ft_font.h | 8 +- src/pdflib/font/ft_generr.h | 8 +- src/pdflib/font/ft_hostfont.c | 2 +- src/pdflib/font/ft_pdffont.c | 2 +- src/pdflib/font/ft_pdffont.h | 2 +- src/pdflib/font/ft_truetype.c | 287 +++++++++++++++++++++++++++--------------- src/pdflib/font/ft_truetype.h | 16 ++- src/pdflib/font/ft_type1.c | 2 +- 13 files changed, 268 insertions(+), 146 deletions(-) (limited to 'src/pdflib/font') diff --git a/src/pdflib/font/ft_cid.c b/src/pdflib/font/ft_cid.c index aff9784..d1815fd 100644 --- a/src/pdflib/font/ft_cid.c +++ b/src/pdflib/font/ft_cid.c @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_cid.c,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_cid.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * FONT CID functions * @@ -57,17 +57,17 @@ static const fnt_cmap_info fnt_predefined_cmaps[] = { "GBK-EUC-V", cc_simplified_chinese, 0, PDC_1_3, 2, 2, 2, 2, 1}, { "GBKp-EUC-H", cc_simplified_chinese, 0, PDC_1_4, 0, 2, 2, 2, 0}, { "GBKp-EUC-V", cc_simplified_chinese, 0, PDC_1_4, 0, 2, 2, 2, 1}, - { "GBK2K-H", cc_simplified_chinese, 0, PDC_1_4, 0, 4, 4, 4, 0}, - { "GBK2K-V", cc_simplified_chinese, 0, PDC_1_4, 0, 4, 4, 4, 1}, + { "GBK2K-H", cc_simplified_chinese, 0, PDC_1_4, 0, 4, 4, 5, 0}, + { "GBK2K-V", cc_simplified_chinese, 0, PDC_1_4, 0, 4, 4, 5, 1}, { "UniGB-UCS2-H", cc_simplified_chinese, 2, PDC_1_3, 2, 4, 4, 4, 0}, { "UniGB-UCS2-V", cc_simplified_chinese, 2, PDC_1_3, 2, 4, 4, 4, 1}, - { "UniGB-UTF16-H", cc_simplified_chinese, 2, PDC_1_5, 0, 0, 4, 4, 0}, - { "UniGB-UTF16-V", cc_simplified_chinese, 2, PDC_1_5, 0, 0, 4, 4, 1}, + { "UniGB-UTF16-H", cc_simplified_chinese, 2, PDC_1_5, 0, 0, 4, 5, 0}, + { "UniGB-UTF16-V", cc_simplified_chinese, 2, PDC_1_5, 0, 0, 4, 5, 1}, { "B5pc-H", cc_traditional_chinese, 0, PDC_1_3, 0, 0, 0, 0, 0}, { "B5pc-V", cc_traditional_chinese, 0, PDC_1_3, 0, 0, 0, 0, 1}, - { "HKscs-B5-H", cc_traditional_chinese, 0, PDC_1_4, 0, 3, 3, 3, 0}, - { "HKscs-B5-V", cc_traditional_chinese, 0, PDC_1_4, 0, 3, 3, 3, 1}, + { "HKscs-B5-H", cc_traditional_chinese, 0, PDC_1_4, 0, 3, 3, 5, 0}, + { "HKscs-B5-V", cc_traditional_chinese, 0, PDC_1_4, 0, 3, 3, 5, 1}, { "ETen-B5-H", cc_traditional_chinese, 0, PDC_1_3, 0, 0, 0, 0, 0}, { "ETen-B5-V", cc_traditional_chinese, 0, PDC_1_3, 0, 0, 0, 0, 1}, { "ETenms-B5-H", cc_traditional_chinese, 0, PDC_1_3, 0, 0, 0, 0, 0}, @@ -94,7 +94,7 @@ static const fnt_cmap_info fnt_predefined_cmaps[] = { "Identity-H", cc_identity, 0, PDC_1_3, 0, 0, 0, 0, 0}, { "Identity-V", cc_identity, 0, PDC_1_3, 0, 0, 0, 0, 1}, - { NULL, 0, 0, 0, 0, 0, 0, 0, 0}, + { NULL, cc_none, 0, 0, 0, 0, 0, 0, 0}, }; static int @@ -246,8 +246,11 @@ fnt_get_maxcid(int charcoll, int supplement) return 22352; case 4: - default: return 29063; + + case 5: + default: + return 30283; } case cc_traditional_chinese: @@ -266,8 +269,11 @@ fnt_get_maxcid(int charcoll, int supplement) return 18845; case 4: - default: return 18964; + + case 5: + default: + return 19087; } case cc_korean: diff --git a/src/pdflib/font/ft_cid.h b/src/pdflib/font/ft_cid.h index 12187cb..db3d5d9 100644 --- a/src/pdflib/font/ft_cid.h +++ b/src/pdflib/font/ft_cid.h @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_cid.h,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_cid.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * CID data structures * diff --git a/src/pdflib/font/ft_corefont.c b/src/pdflib/font/ft_corefont.c index b368f67..cf9dd15 100644 --- a/src/pdflib/font/ft_corefont.c +++ b/src/pdflib/font/ft_corefont.c @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_corefont.c,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_corefont.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * FONT in-core and basic font metric functions * diff --git a/src/pdflib/font/ft_corefont.h b/src/pdflib/font/ft_corefont.h index 526212e..cfc658b 100644 --- a/src/pdflib/font/ft_corefont.h +++ b/src/pdflib/font/ft_corefont.h @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_corefont.h,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_corefont.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * This file contains the metric for the base and * pre-installed CID fonts of PDF @@ -2617,7 +2617,8 @@ static const char *fnt_cid_width_arrays[] = "814 939 500\n" "7712[517 684 723]\n" "7716[500]\n" - "22353[462 462 500 500 500]\n", + "22353[462 462 500 500 500]\n" + "29064 30283 550\n", /*------------------------------------------------------------------------*/ diff --git a/src/pdflib/font/ft_font.c b/src/pdflib/font/ft_font.c index 53a39a9..58f1cf6 100644 --- a/src/pdflib/font/ft_font.c +++ b/src/pdflib/font/ft_font.c @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_font.c,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_font.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * FONT basic font functions * @@ -393,10 +393,11 @@ pdc_encodingvector * fnt_create_font_ev(pdc_core *pdc, fnt_font *font) { pdc_encodingvector *ev = NULL; - char encname[128]; + char encname[PDC_GEN_BUFSIZE]; pdc->uniqueno++; - sprintf(encname, "encoding_%s_%d", font->name, pdc->uniqueno); + pdc_sprintf(pdc, pdc_false, encname, "encoding_%s_%d", + font->name, pdc->uniqueno); ev = pdc_new_encoding(pdc, encname); pdc_insert_encoding_vector(pdc, ev); font->enc = pdc_find_encoding(pdc, encname); @@ -424,24 +425,35 @@ fnt_check_weight(int weight) static const pdc_keyconn fnt_fontweight_keylist[] = { - {"none", FNT_FW_DONTCARE}, - {"thin", FNT_FW_THIN}, - {"extralight", FNT_FW_EXTRALIGHT}, - {"ultralight", FNT_FW_ULTRALIGHT}, - {"light", FNT_FW_LIGHT}, - {"normal", FNT_FW_NORMAL}, - {"regular", FNT_FW_REGULAR}, + {"None", FNT_FW_DONTCARE}, + {"Thin", FNT_FW_THIN}, + {"Extralight", FNT_FW_EXTRALIGHT}, + {"Ultralight", FNT_FW_ULTRALIGHT}, + {"Light", FNT_FW_LIGHT}, + {"Normal", FNT_FW_NORMAL}, + {"Regular", FNT_FW_REGULAR}, {"", FNT_FW_REGULAR}, - {"medium", FNT_FW_MEDIUM}, - {"semibold", FNT_FW_SEMIBOLD}, - {"semi", FNT_FW_SEMIBOLD}, - {"demibold", FNT_FW_DEMIBOLD}, - {"bold", FNT_FW_BOLD}, - {"extrabold", FNT_FW_EXTRABOLD}, - {"extra", FNT_FW_EXTRABOLD}, - {"ultrabold", FNT_FW_ULTRABOLD}, - {"heavy", FNT_FW_HEAVY}, - {"black", FNT_FW_BLACK}, + {"Medium", FNT_FW_MEDIUM}, + {"Semibold", FNT_FW_SEMIBOLD}, + {"Semi", FNT_FW_SEMIBOLD}, + {"Demibold", FNT_FW_DEMIBOLD}, + {"Bold", FNT_FW_BOLD}, + {"Extrabold", FNT_FW_EXTRABOLD}, + {"Extra", FNT_FW_EXTRABOLD}, + {"Ultrabold", FNT_FW_ULTRABOLD}, + {"Heavy", FNT_FW_HEAVY}, + {"Black", FNT_FW_BLACK}, + {"0", FNT_FW_DONTCARE}, + {"100", FNT_FW_THIN}, + {"200", FNT_FW_EXTRALIGHT}, + {"300", FNT_FW_LIGHT}, + {"400", FNT_FW_NORMAL}, + {"500", FNT_FW_MEDIUM}, + {"600", FNT_FW_SEMIBOLD}, + {"700", FNT_FW_BOLD}, + {"800", FNT_FW_EXTRABOLD}, + {"900", FNT_FW_BLACK}, + {NULL, 0} }; diff --git a/src/pdflib/font/ft_font.h b/src/pdflib/font/ft_font.h index 34f2a0b..73da0e6 100644 --- a/src/pdflib/font/ft_font.h +++ b/src/pdflib/font/ft_font.h @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_font.h,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_font.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * Header file for font handling * @@ -77,12 +77,18 @@ #define FNT_SMALLCAPS (long) (1L<<17) #define FNT_FORCEBOLD (long) (1L<<18) +#define FNT_FI_ITALIC 255 +#define FNT_FI_ITALICNAME "Italic" #define FNT_DEF_ITALICANGLE -12 /* default italic angle */ + #define FNT_MISSING_FONTVAL PDC_SHRT_MIN /* missing font value */ /* start sequence of PFA files */ #define FNT_PFA_STARTSEQU "%!PS" +/* missing file name for font outline data */ +#define FNT_MISSING_FILENAME "__missing__filename__" + /* Font types */ typedef enum { diff --git a/src/pdflib/font/ft_generr.h b/src/pdflib/font/ft_generr.h index 909596b..be9a4fc 100644 --- a/src/pdflib/font/ft_generr.h +++ b/src/pdflib/font/ft_generr.h @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_generr.h,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_generr.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * FONT error messages * @@ -38,9 +38,13 @@ gen(1, 7001, FONT_PREFIX, "Font '$1': ") gen(0, 7002, FONT_HOSTNOTFOUND, "Host font not found") +gen(0, 7003, FONT_HOSTNOTFOUND2, + "Host font not found (maybe unsupported QuickDraw font name specified)") + gen(1, 7004, FONT_UNSUPP_FORMAT, "Font format '$1' not supported") -gen(0, 7006, FONT_TTHOSTNOTFOUND, "TrueType host font not found") +gen(2, 7006, FONT_HOSTNOTLOADED, + "Couldn't load $1 host font (system error code $2)") gen(1, 7007, FONT_NAMETOOLONG, "Font name too long (max. $1 characters)") diff --git a/src/pdflib/font/ft_hostfont.c b/src/pdflib/font/ft_hostfont.c index ec9411d..7f8970a 100644 --- a/src/pdflib/font/ft_hostfont.c +++ b/src/pdflib/font/ft_hostfont.c @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_hostfont.c,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_hostfont.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * FONT host font handling routines for Windows and Mac * diff --git a/src/pdflib/font/ft_pdffont.c b/src/pdflib/font/ft_pdffont.c index 0767d74..278e1ba 100644 --- a/src/pdflib/font/ft_pdffont.c +++ b/src/pdflib/font/ft_pdffont.c @@ -6,7 +6,7 @@ | Proprietary source code -- do not redistribute! | *---------------------------------------------------------------------------*/ -/* $Id: ft_pdffont.c,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_pdffont.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * Routine for parsing font dictionaries in PDF files by pCOS * diff --git a/src/pdflib/font/ft_pdffont.h b/src/pdflib/font/ft_pdffont.h index bb40cbc..c0c5b7a 100644 --- a/src/pdflib/font/ft_pdffont.h +++ b/src/pdflib/font/ft_pdffont.h @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_pdffont.h,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_pdffont.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * Header file for parsing font dictionaries in PDF files * diff --git a/src/pdflib/font/ft_truetype.c b/src/pdflib/font/ft_truetype.c index b4e33a6..8aa437c 100644 --- a/src/pdflib/font/ft_truetype.c +++ b/src/pdflib/font/ft_truetype.c @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_truetype.c,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_truetype.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * FONT TrueType handling routines * @@ -198,14 +198,13 @@ tt_get_offset(tt_file *ttf, tt_byte offsize) static void tt_get_dirent(tt_dirent *dirent, tt_file *ttf) { - tt_read(ttf, dirent->tag, 4); - dirent->tag[4] = 0; + tt_read(ttf, dirent->tag, TT_TABTAG_SIZE); + dirent->tag[TT_TABTAG_SIZE] = 0; dirent->checksum = tt_get_ulong(ttf); dirent->offset = tt_get_ulong(ttf); dirent->length = tt_get_ulong(ttf); } /* tt_get_dirent */ - int tt_tag2idx(tt_file *ttf, char *tag) { @@ -233,6 +232,10 @@ tt_get_tab(tt_file *ttf, char *tag, size_t nbytes, pdc_bool tterror, return NULL; } + pdc_logg_cond(pdc, 3, trc_font, + "\t\treading table \"%s\" (offset=0x%05X, length=%d)\n", + tag, ttf->dir[idx].offset, ttf->dir[idx].length); + tt_seek(ttf, (long) ttf->dir[idx].offset); if (offset) @@ -298,6 +301,28 @@ tt_get_cmap6(tt_file *ttf, tt_cmap0_6 *cm0_6) } /* tt_get_cmap6 */ static void +tt_cleanup_cmap4(tt_file *ttf, tt_cmap4 *cm4) +{ + pdc_core *pdc = ttf->pdc; + + if (cm4 != (tt_cmap4 *) 0) + { + if (cm4->endCount != (tt_ushort *) 0) + pdc_free(pdc, cm4->endCount); + if (cm4->startCount != (tt_ushort *) 0) + pdc_free(pdc, cm4->startCount); + if (cm4->idDelta != (tt_short *) 0) + pdc_free(pdc, cm4->idDelta); + if (cm4->idRangeOffs != (tt_ushort *) 0) + pdc_free(pdc, cm4->idRangeOffs); + if (cm4->glyphIdArray != (tt_ushort *) 0) + pdc_free(pdc, cm4->glyphIdArray); + + pdc_free(pdc, cm4); + } +} + +static tt_cmap4 * tt_get_cmap4(tt_file *ttf, tt_cmap4 *cm4) { static const char *fn = "tt_get_cmap4"; @@ -321,63 +346,57 @@ tt_get_cmap4(tt_file *ttf, tt_cmap4 *cm4) segs = cm4->segCountX2 / 2; - cm4->numGlyphIds = (tt_ushort)( - ((cm4->length - ( 16L + 8L * segs )) & 0xFFFFU) / 2); + if (segs >= 1) + { + cm4->numGlyphIds = (tt_ushort)( + ((cm4->length - ( 16L + 8L * segs )) & 0xFFFFU) / 2); - TT_IOCHECK(ttf, 0 <= cm4->numGlyphIds); + TT_IOCHECK(ttf, 0 <= cm4->numGlyphIds); - cm4->endCount = - (tt_ushort *) - pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn); - cm4->startCount = - (tt_ushort *) - pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn); - cm4->idDelta = - (tt_short *) - pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn); - cm4->idRangeOffs = - (tt_ushort *) - pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn); + cm4->endCount = + (tt_ushort *) + pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn); + cm4->startCount = + (tt_ushort *) + pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn); + cm4->idDelta = + (tt_short *) + pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn); + cm4->idRangeOffs = + (tt_ushort *) + pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn); - if (cm4->numGlyphIds) - { - cm4->glyphIdArray = (tt_ushort *) - pdc_malloc(pdc, - (size_t) (sizeof (tt_ushort) * cm4->numGlyphIds), fn); - } + if (cm4->numGlyphIds) + { + cm4->glyphIdArray = (tt_ushort *) + pdc_malloc(pdc, + (size_t) (sizeof (tt_ushort) * cm4->numGlyphIds), fn); + } - for (i = 0; i < segs; ++i) - cm4->endCount[i] = tt_get_ushort(ttf); + for (i = 0; i < segs; ++i) + cm4->endCount[i] = tt_get_ushort(ttf); - TT_IOCHECK(ttf, cm4->endCount[segs - 1] == 0xFFFF); + TT_IOCHECK(ttf, cm4->endCount[segs - 1] == 0xFFFF); - (void) tt_get_ushort(ttf); /* padding */ - for (i = 0; i < segs; ++i) cm4->startCount[i] = tt_get_ushort(ttf); - for (i = 0; i < segs; ++i) cm4->idDelta[i] = tt_get_short(ttf); - for (i = 0; i < segs; ++i) cm4->idRangeOffs[i] = tt_get_ushort(ttf); + (void) tt_get_ushort(ttf); /* padding */ + for (i = 0; i < segs; ++i) cm4->startCount[i] = tt_get_ushort(ttf); + for (i = 0; i < segs; ++i) cm4->idDelta[i] = tt_get_short(ttf); + for (i = 0; i < segs; ++i) cm4->idRangeOffs[i] = tt_get_ushort(ttf); - for (i = 0; i < cm4->numGlyphIds; ++i) - cm4->glyphIdArray[i] = tt_get_ushort(ttf); + for (i = 0; i < cm4->numGlyphIds; ++i) + cm4->glyphIdArray[i] = tt_get_ushort(ttf); + } /* empty cmap */ - if (segs == 1 && cm4->endCount[0] == cm4->startCount[0]) - { - cm4->segCountX2 = 0; - pdc_free(pdc, cm4->endCount); - cm4->endCount = (tt_ushort *) 0; - pdc_free(pdc, cm4->startCount); - cm4->startCount = (tt_ushort *) 0; - pdc_free(pdc, cm4->idDelta); - cm4->idDelta = (tt_short *) 0; - pdc_free(pdc, cm4->idRangeOffs); - cm4->idRangeOffs = (tt_ushort *) 0; - if (cm4->numGlyphIds) - { - pdc_free(pdc, cm4->glyphIdArray); - cm4->glyphIdArray = (tt_ushort *) 0; - } + if (segs == 0 || (segs == 1 && cm4->endCount[0] == cm4->startCount[0])) + { + tt_cleanup_cmap4(ttf, cm4); + + cm4 = (tt_cmap4 *) 0; } + return cm4; + } /* tt_get_cmap4 */ @@ -452,6 +471,8 @@ tt_get_tab_cmap(tt_file *ttf) pdc_malloc(pdc, sizeof (tt_cmap0_6), fn); tp->mac->format = 0; tt_get_cmap0(ttf, tp->mac); + + offset_mac = offsetEncTab; } else if (tableFormat == 6 && tp->mac == (tt_cmap0_6 *) 0) { @@ -459,53 +480,67 @@ tt_get_tab_cmap(tt_file *ttf) pdc_malloc(pdc, sizeof (tt_cmap0_6), fn); tp->mac->format = 6; tt_get_cmap6(ttf, tp->mac); + + offset_mac = offsetEncTab; } - offset_mac = offsetEncTab; + else if (numEncTabs == 1 && tableFormat == 4) + { + /* simulating Windows */ + tp->win = (tt_cmap4 *) pdc_malloc(pdc, sizeof (tt_cmap4), fn); + tp->win->format = tableFormat; + tp->win->encodingID = encodingID; + tp->win = tt_get_cmap4(ttf, tp->win); + + /* cmap picking not necessary */ + } } /* - * platformID: 0 encodingID: 3 tableFormat: 4 (old mac) - * platformID: 3 encodingID: 0/1 tableFormat: 4 + * platformID: 0 encodingID: 3 tableFormat: 4 (old mac) + * platformID: 3 encodingID: 0/1/4 tableFormat: 4 preferred! */ - else if ((tp->win == (tt_cmap4 *) 0 && tableFormat == 4) && + else if (tableFormat == 4 && ((platformID == tt_pfid_win && (encodingID == tt_wenc_symbol || - encodingID == tt_wenc_text)) || + encodingID == tt_wenc_text || + encodingID == tt_wenc_big5)) || (platformID == tt_pfid_uni && encodingID == tt_wenc_mtext))) { - tp->win = (tt_cmap4 *) pdc_malloc(pdc, sizeof (tt_cmap4), fn); - tp->win->format = tableFormat; - - /* we suppose a windows platform (see old mac hostfont Times) */ - if (encodingID == tt_wenc_mtext) + if (tp->win == (tt_cmap4 *) 0 || + (tp->win != (tt_cmap4 *) 0 && + ((tp->win->encodingID == tt_wenc_mtext || + tp->win->encodingID == tt_wenc_big5) && + encodingID < tt_wenc_mtext))) { - encodingID = tt_wenc_text; - } - - tt_get_cmap4(ttf, tp->win); + if (tp->win != (tt_cmap4 *) 0) + tt_cleanup_cmap4(ttf, tp->win); + tp->win = (tt_cmap4 *) pdc_malloc(pdc, sizeof (tt_cmap4), fn); - if (tp->win->segCountX2) - { + tp->win->format = tableFormat; tp->win->encodingID = encodingID; + tp->win = tt_get_cmap4(ttf, tp->win); + + if (tp->win != (tt_cmap4 *) 0) + offset_win = offsetEncTab; } - else - { - pdc_free(pdc, tp->win); - tp->win = (tt_cmap4 *) 0; - } - offset_win = offsetEncTab; } tt_seek(ttf, pos); } /* for */ + /* we suppose a windows platform (see old mac hostfont Times) */ + if (tp->win && tp->win->encodingID == tt_wenc_mtext) + { + encodingID = tt_wenc_text; + } + /* is symbol font */ ttf->issymbol = (tp->win && tp->win->encodingID == tt_wenc_symbol) ? pdc_true : pdc_false; - /* has Unicode cmap */ + /* has Unicode/CMap cmap */ ttf->haswinuni = (!ttf->issymbol && (tp->win || tp->ucs4)) ? pdc_true : pdc_false; @@ -540,6 +575,7 @@ tt_get_tab_cmap(tt_file *ttf) } else { + ttf->hasbig5cmap = tp->win->encodingID == tt_wenc_big5; tp->encoding = tt_wenc_text; tp->format = tp->win->format; tp->offset = offset_win; @@ -553,12 +589,16 @@ tt_get_tab_cmap(tt_file *ttf) tp->platform, tp->encoding, tp->format, ttf->issymbol ? "symbol" : "text"); + if (ttf->hasbig5cmap) + pdc_logg_cond(ttf->pdc, 1, trc_font, "\t\tCID font with Big5 cmap\n"); + /* for subsetting and symbolic font: * tp->platform = tt_pfid_mac according PDF specification * otherwise GS will emit an error message */ if (ttf->issymbol && offset_mac > 0) { + ttf->forcesubset = !ttf->hasonlymac; tp->platform = tt_pfid_mac; tp->encoding = tt_wenc_symbol; tp->format = tp->mac->format; @@ -600,7 +640,7 @@ tt_get_tab_head(tt_file *ttf) tp->glyphDataFormat = tt_get_short(ttf); } /* tt_get_tab_head */ -static void +void tt_get_tab_hhea(tt_file *ttf) { tt_tab_hhea *tp = NULL; @@ -764,7 +804,6 @@ tt_get_tab_name(tt_file *ttf) tp->englishname4 = NULL; tp->englishname6 = NULL; tp->producer = NULL; - tp->format = tt_get_ushort(ttf); /* Format 0 is the only document one, but some Apple fonts use 65535. @@ -782,6 +821,13 @@ tt_get_tab_name(tt_file *ttf) "\tRecords in name table of format %d: %d:\n", tp->format, tp->numNameRecords); + if (ttf->utf16fontname != NULL) + { + pdc_logg_cond(pdc, 1, trc_font, + "\tSearching for a host font with Unicode name \"%T\"\n", + ttf->utf16fontname, ttf->fnamelen); + } + /* this was observed. we ignore it in TET */ if (ttf->fortet && tp->numNameRecords == 0) return pdc_true; @@ -865,7 +911,7 @@ tt_get_tab_name(tt_file *ttf) if (namerec->length && namerec->namid == namid) { /* TTC font search */ - if (ttf->utf16fontname) + if (ttf->utf16fontname != NULL) { /* read font name */ if (localname == NULL) @@ -925,7 +971,7 @@ tt_get_tab_name(tt_file *ttf) } /* TTC font not found */ - if (ttf->utf16fontname) + if (ttf->utf16fontname != NULL) return pdc_false; /* English font names */ @@ -1018,6 +1064,7 @@ void tt_get_tab_OS_2(tt_file *ttf) { pdc_bool logg3 = pdc_logg_is_enabled(ttf->pdc, 3, trc_font); + pdc_bool logg5 = pdc_logg_is_enabled(ttf->pdc, 5, trc_font); int i, j; tt_tab_OS_2 *tp = NULL; @@ -1077,7 +1124,8 @@ tt_get_tab_OS_2(tt_file *ttf) for (i = 0; i < PDC_NUMCHARCOLL; i++) { j = i + 17; - if (tp->ulCodePageRange1 & (1<ulCodePageRange1 & (1<hasbig5cmap && + tt_cpflag2charcoll[i] == cc_traditional_chinese)) tp->charcolls[i] = tt_cpflag2charcoll[i]; else tp->charcolls[i] = cc_none; @@ -1100,6 +1148,15 @@ tt_get_tab_OS_2(tt_file *ttf) tp->usMaxContext = 0; } + if (logg5) + { + pdc_logg(ttf->pdc, "\t\t\tusFirstCharIndex=0x%04X\n", + ttf->tab_OS_2->usFirstCharIndex); + if (ttf->tab_cmap && ttf->tab_cmap->win) + pdc_logg(ttf->pdc, "\t\t\tstartCount[0]=0x%04X\n", + ttf->tab_cmap->win->startCount[0]); + } + /* there are fonts with inconsistent usFirstCharIndex */ if (ttf->tab_cmap && ttf->tab_cmap->win && tp->usFirstCharIndex != ttf->tab_cmap->win->startCount[0]) @@ -1191,7 +1248,12 @@ tt_get_tab_post(tt_file *ttf) tp->maxMemType42 = tt_get_ulong(ttf); tp->minMemType1 = tt_get_ulong(ttf); tp->maxMemType1 = tt_get_ulong(ttf); + tp->numberOfGlyphs = ttf->numGlyphs; + /* there are subset fonts with different number of glyphs + * see bug #1418 + */ + ttf->numGlyphs = MAX(tp->numberOfGlyphs, ttf->numGlyphs); } /* tt_get_tab_post */ @@ -1279,6 +1341,7 @@ fnt_test_tt_font(pdc_core *pdc, tt_byte *img, tt_ulong *n_fonts, return pdc_true; } + pdc_bool fnt_is_opentype_font(tt_file *ttf) { @@ -1387,22 +1450,43 @@ tt_unicode2gidx(tt_file *ttf, int usv, pdc_bool logg) pdc_core *pdc = ttf->pdc; tt_cmap4 *cm4 = ttf->tab_cmap->win; pdc_ushort uv; - int segs; - int gidx = 0; - int i; + int lo, hi, segs; + int gidx = 0, i = 0; uv = (pdc_ushort) usv; - if (logg) pdc_logg(pdc, "\t\t\tU+%04X: ", uv); + if (logg) pdc_logg(pdc, "\t\t\tUCS2: %04X: ", uv); segs = cm4->segCountX2 / 2; - for (i = 0; i < segs; ++i) + lo = 0; + hi = segs; + while (lo < hi) + { + i = (lo + hi) / 2; + if (uv <= cm4->endCount[i]) - break; + { + if (uv >= cm4->startCount[i]) + { + break; + } + else if (!i || uv > cm4->endCount[i - 1]) + { + i = -1; + break; + } + } + + if (uv < cm4->startCount[i]) + hi = i; + else + lo = i + 1; + } - if (logg) pdc_logg(pdc, "i=%d start=U+%04X ", i, cm4->startCount[i]); + + if (logg) pdc_logg(pdc, "i=%d start=UCS2: %04X ", i, cm4->startCount[i]); TT_IOCHECK(ttf, i != segs); - if (uv < cm4->startCount[i] || uv == 0xFFFF) + if (i == -1 || uv == 0xFFFF) { if (logg) pdc_logg(pdc, "==> gidx=0\n"); return 0; @@ -1478,12 +1562,16 @@ tt_gidx2width(tt_file *ttf, int gidx) void fnt_set_tt_fontvalues(tt_file *ttf) { + pdc_bool logg3 = pdc_logg_is_enabled(ttf->pdc, 3, trc_font); fnt_font *font = ttf->font; fnt_font_metric *ftm = &font->m; if (ttf->onlyCFF) return; + if (logg3) + pdc_logg(ttf->pdc, "\tUnits per EM: %d\n", ttf->tab_head->unitsPerEm); + if (ttf->tab_head) { ftm->llx = FNT_TT2PDF(ttf->tab_head->xMin); @@ -1601,6 +1689,9 @@ fnt_set_tt_fontarrays(tt_file *ttf, int flags) ** like that; perhaps we have to apply similar tricks then... */ uvoffset = (ttf->tab_OS_2->usFirstCharIndex & 0xFF00); + + if (logg5) + pdc_logg(pdc, "\t\tuvoffset=0x%04X\n", uvoffset); } else { @@ -2140,6 +2231,8 @@ fnt_check_tt_font(pdc_core *pdc, const char *filename, const char *fontname, * ttf->verbose = pdc_false; * ttf->kerning = pdc_true; * ttf->vertical = pdc_true; + * ttf->ignorename = pdc_true; + * ttf->cmst = ~NULL; * ttf->fortet = pdc_true; * * ttf->check = pdc_true; @@ -2201,6 +2294,9 @@ fnt_new_tt(pdc_core *pdc, fnt_font *font) ttf->issymbol = pdc_false; ttf->haswinuni = pdc_false; ttf->hasonlymac = pdc_false; + ttf->hasbig5cmap = pdc_false; + ttf->forcesubset = pdc_false; + ttf->gidunequcid = pdc_false; ttf->utf16fontname = (char *) 0; @@ -2214,9 +2310,6 @@ void fnt_delete_tt(tt_file *ttf) { pdc_core *pdc = ttf->pdc; - int i; - - (void) i; if (ttf->check == pdc_false && ttf->fp != (pdc_file *) 0) pdc_fclose(ttf->fp); @@ -2243,24 +2336,14 @@ fnt_delete_tt(tt_file *ttf) if (ttf->tab_cmap != (tt_tab_cmap *) 0) { - if (ttf->tab_cmap->mac != (tt_cmap0_6 *) 0) { + if (ttf->tab_cmap->mac != (tt_cmap0_6 *) 0) + { if (ttf->tab_cmap->mac->glyphIdArray) pdc_free(pdc, ttf->tab_cmap->mac->glyphIdArray); pdc_free(pdc, ttf->tab_cmap->mac); } - if (ttf->tab_cmap->win != (tt_cmap4 *) 0) - { - tt_cmap4 *cm4 = (tt_cmap4 *) ttf->tab_cmap->win; - - if (cm4->endCount != 0) pdc_free(pdc, cm4->endCount); - if (cm4->startCount != 0) pdc_free(pdc, cm4->startCount); - if (cm4->idDelta != 0) pdc_free(pdc, cm4->idDelta); - if (cm4->idRangeOffs != 0) pdc_free(pdc, cm4->idRangeOffs); - if (cm4->glyphIdArray != 0) pdc_free(pdc, cm4->glyphIdArray); - - pdc_free(pdc, cm4); - } + tt_cleanup_cmap4(ttf, ttf->tab_cmap->win); if (ttf->tab_cmap->ucs4 != (tt_cmap12 *) 0) { diff --git a/src/pdflib/font/ft_truetype.h b/src/pdflib/font/ft_truetype.h index 89cd3fb..eda7513 100644 --- a/src/pdflib/font/ft_truetype.h +++ b/src/pdflib/font/ft_truetype.h @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_truetype.h,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_truetype.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * FONT TrueType typedefs, structures, and enums * @@ -44,6 +44,7 @@ typedef unsigned short tt_ufword; #define TT_NUMEXPSTRINGS 379 #define TT_NUMEXPERTGIDS 166 +#define TT_TABTAG_SIZE 4 #define TT_OFFSETTAB_SIZE 12 /* flags for fnt_set_tt_fontarrays */ @@ -55,6 +56,7 @@ typedef unsigned short tt_ufword; #define TT_FONT_m_widths (1<<5) #define TT_FONT_names (1<<6) #define TT_FONT_name2unitab (1<<7) +#define TT_FONT_gid2cid (1<<8) typedef enum { @@ -124,7 +126,7 @@ tt_cff_oper; typedef struct { - char tag[5]; + char tag[TT_TABTAG_SIZE + 1]; tt_ulong checksum; tt_ulong offset; tt_ulong length; @@ -143,7 +145,9 @@ typedef enum { tt_wenc_symbol = 0, tt_wenc_text = 1, + tt_wenc_sjis = 2, tt_wenc_mtext = 3, + tt_wenc_big5 = 4, tt_wenc_utext = 10 } tt_win_encoding_id; @@ -457,10 +461,13 @@ typedef struct pdc_bool issymbol; /* symbol font */ pdc_bool haswinuni; /* has a "Microsoft standard character * to glyph index mapping table" - * cmap (3, 1) format 4 or + * cmap (3, 1, 4) format 4 or * cmap (3,10) format 12 or * cmap (0, 3) format 4 (mac old case) */ pdc_bool hasonlymac; /* has only macroman cmap (0,1) */ + pdc_bool hasbig5cmap; /* has Big5 cmap cmap (3,4) */ + pdc_bool forcesubset; /* subset will be forced to set unique cmap */ + pdc_bool gidunequcid; /* GID != SID */ char *utf16fontname; /* UTF-16-BE font name for TTC fonts */ int fnamelen; /* font name length */ @@ -508,6 +515,7 @@ typedef struct /* Functions */ #define FNT_TT2PDF(v) (int) PDC_ROUND(v * 1000.0 / ttf->tab_head->unitsPerEm) +#define FNT_PDF2TT(v) (int) (v * ttf->tab_head->unitsPerEm / 1000.0) #define TT_ASSERT(ttf, cond) \ ((cond) ? (void) 0 : tt_assert(ttf)) @@ -520,6 +528,7 @@ void *tt_get_tab(tt_file *ttf, char *tag, size_t nbytes, pdc_bool tterror, tt_ulong *offset); void tt_get_tab_maxp(tt_file *ttf); void tt_get_tab_head(tt_file *ttf); +void tt_get_tab_hhea(tt_file *ttf); void tt_get_tab_cmap(tt_file *ttf); pdc_bool tt_get_tab_CFF_(tt_file *ttf); void tt_get_tab_OS_2(tt_file *ttf); @@ -555,4 +564,5 @@ pdc_bool fnt_check_tt_font(pdc_core *pdc, const char *filename, const char *fontname, fnt_font *font, pdc_bool requested); + #endif /* FT_TRUETYPE_H */ diff --git a/src/pdflib/font/ft_type1.c b/src/pdflib/font/ft_type1.c index 2644284..6c16102 100644 --- a/src/pdflib/font/ft_type1.c +++ b/src/pdflib/font/ft_type1.c @@ -10,7 +10,7 @@ | | *---------------------------------------------------------------------------*/ -/* $Id: ft_type1.c,v 1.1 2008/10/17 06:10:43 scuri Exp $ +/* $Id: ft_type1.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ * * FONT Type1 font handling routines * -- cgit v1.2.3