HPDF_INT16
HPDF_Type1FontDef_GetWidthByName  (HPDF_FontDef      fontdef,
                                   const char*  gryph_name)
{
    HPDF_UNICODE unicode = HPDF_GryphNameToUnicode (gryph_name);

    HPDF_PTRACE (" HPDF_Type1FontDef_GetWidthByName\n");

    return HPDF_Type1FontDef_GetWidth (fontdef, unicode);
}
示例#2
0
文件: hpdf_font.c 项目: xharbour/core
HPDF_Font_GetUnicodeWidth  (HPDF_Font       font,
                            HPDF_UNICODE    code)
{
    HPDF_FontAttr attr;
    HPDF_FontDef fontdef;

    HPDF_PTRACE((" HPDF_Font_GetUnicodeWidth\n"));

    if (!HPDF_Font_Validate(font))
        return 0;

    attr = (HPDF_FontAttr)font->attr;
    fontdef = attr->fontdef;

    if (fontdef->type == HPDF_FONTDEF_TYPE_TYPE1) {
        return HPDF_Type1FontDef_GetWidth (fontdef, code);
    } else if (fontdef->type == HPDF_FONTDEF_TYPE_TRUETYPE) {
        return HPDF_TTFontDef_GetCharWidth (fontdef, code);
    } else if (fontdef->type == HPDF_FONTDEF_TYPE_CID) {
        HPDF_CMapEncoderAttr encoder_attr =
            (HPDF_CMapEncoderAttr)attr->encoder->attr;
        HPDF_UINT l, h;

        for (l = 0; l <= 255; l++) {
            for (h = 0; h < 255; h++) {
                if (code == encoder_attr->unicode_map[l][h]) {
                    HPDF_UINT16 cid = encoder_attr->cid_map[l][h];

                    return HPDF_CIDFontDef_GetCIDWidth (fontdef, cid);
                }
            }
        }
    }

    HPDF_PTRACE((" HPDF_Font_GetUnicodeWidth not found (0x%04X)\n", code));

    return 0;
}
示例#3
0
HPDF_Font
HPDF_Type1Font_New  (HPDF_MMgr        mmgr,
                     HPDF_FontDef     fontdef,
                     HPDF_Encoder     encoder,
                     HPDF_Xref        xref)
{
    HPDF_Dict font;
    HPDF_FontAttr attr;
    HPDF_Type1FontDefAttr fontdef_attr;
    HPDF_BasicEncoderAttr encoder_attr;
    HPDF_STATUS ret = 0;
    HPDF_UINT i;

    HPDF_PTRACE ((" HPDF_Type1Font_New\n"));

    /* check whether the fontdef object and the encoder object is valid. */
    if (encoder->type != HPDF_ENCODER_TYPE_SINGLE_BYTE) {
        HPDF_SetError(mmgr->error, HPDF_INVALID_ENCODER_TYPE, 0);
        return NULL;
    }

    if (fontdef->type != HPDF_FONTDEF_TYPE_TYPE1) {
        HPDF_SetError(mmgr->error, HPDF_INVALID_FONTDEF_TYPE, 0);
        return NULL;
    }

    font = HPDF_Dict_New (mmgr);
    if (!font)
        return NULL;

    font->header.obj_class |= HPDF_OSUBCLASS_FONT;

    attr = HPDF_GetMem (mmgr, sizeof(HPDF_FontAttr_Rec));
    if (!attr) {
        HPDF_Dict_Free (font);
        return NULL;
    }

    font->header.obj_class |= HPDF_OSUBCLASS_FONT;
    font->write_fn = Type1Font_OnWrite;
    font->free_fn = Type1Font_OnFree;

    HPDF_MemSet (attr, 0, sizeof(HPDF_FontAttr_Rec));

    font->attr = attr;
    attr->type = HPDF_FONT_TYPE1;
    attr->writing_mode = HPDF_WMODE_HORIZONTAL;
    attr->text_width_fn = Type1Font_TextWidth;
    attr->measure_text_fn = Type1Font_MeasureText;
    attr->fontdef = fontdef;
    attr->encoder = encoder;
    attr->xref = xref;

    /* singlebyte-font has a widths-array which is an array of 256 signed
     * short integer.
     */
    attr->widths = HPDF_GetMem (mmgr, sizeof(HPDF_INT16) * 256);
    if (!attr->widths) {
        HPDF_Dict_Free (font);
        return NULL;
    }

    encoder_attr = (HPDF_BasicEncoderAttr)encoder->attr;

    HPDF_MemSet (attr->widths, 0, sizeof(HPDF_INT16) * 256);
    for (i = encoder_attr->first_char; i <= encoder_attr->last_char; i++) {
        HPDF_UNICODE u = encoder_attr->unicode_map[i];

        HPDF_UINT16 w = HPDF_Type1FontDef_GetWidth (fontdef, u);
        attr->widths[i] = w;
    }

    fontdef_attr = (HPDF_Type1FontDefAttr)fontdef->attr;

    if(strncmp (fontdef->base_font, "HPDF_", 5) == 0 && fontdef->is_form_font == HPDF_TRUE)
    {
        ret += HPDF_Dict_AddName (font, "Type", "Font");
        ret += HPDF_Dict_AddName (font, "BaseFont", fontdef->base_font + 5);
        ret += HPDF_Dict_AddName (font, "Subtype", "TrueType");
    }
    else{
        ret += HPDF_Dict_AddName (font, "Type", "Font");
        ret += HPDF_Dict_AddName (font, "BaseFont", fontdef->base_font);
        ret += HPDF_Dict_AddName (font, "Subtype", "Type1");
    }
    if (!fontdef_attr->is_base14font) {
        if (fontdef->missing_width != 0)
            ret += HPDF_Dict_AddNumber (font, "MissingWidth",
                    fontdef->missing_width);

        ret += Type1Font_CreateDescriptor (mmgr, font, xref);
    }

    if (ret != HPDF_OK) {
        HPDF_Dict_Free (font);
        return NULL;
    }

    if (HPDF_Xref_Add (xref, font) != HPDF_OK)
        return NULL;

    return font;
}