Beispiel #1
0
int
i_t1_face_name(i_t1_font_t font, char *name_buf, size_t name_buf_size) {
  char *name;
  int font_num = font->font_id;

  i_mutex_lock(mutex);

  T1_errno = 0;
  if (T1_LoadFont(font_num)) {
    t1_push_error();
    i_mutex_unlock(mutex);
    return 0;
  }
  name = T1_GetFontName(font_num);

  if (name) {
    size_t len = strlen(name);
    strncpy(name_buf, name, name_buf_size);
    name_buf[name_buf_size-1] = '\0';
    i_mutex_unlock(mutex);
    return len + 1;
  }
  else {
    t1_push_error();
    i_mutex_unlock(mutex);
    return 0;
  }
}
Beispiel #2
0
SWFFONT* swf_LoadT1Font(const char*filename)
{
    SWFFONT * font;
    int nr;
    float angle,underline;
    char*fontname,*fullname,*familyname;
    BBox bbox;
    int s,num;
    char**charnames;
    char**charname;
    char*encoding[256];
    int c;
    int t;

    if(!t1lib_initialized) {
	T1_SetBitmapPad(16);
	if ((T1_InitLib(NO_LOGFILE)==NULL)){
	    fprintf(stderr, "Initialization of t1lib failed\n");
	    return 0;
	}
	t1lib_initialized = 1;
    }
    nr = T1_AddFont(filename);
    T1_LoadFont(nr);

    charnames = T1_GetAllCharNames(nr);
    if(!charnames) {
	fprintf(stderr, "No Charnames record- not a Type1 Font?\n");
	return 0;
    }

    angle = T1_GetItalicAngle(nr);
    fontname = T1_GetFontName(nr);
    fullname = T1_GetFullName(nr);
    familyname = T1_GetFamilyName(nr);
    underline = T1_GetUnderlinePosition(nr);
    bbox = T1_GetFontBBox(nr);

    font = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));

    font->version = 2;
    if(fontname) 
	font->name = (U8*)strdup(fontname);
    else 
	font->name = 0;
    font->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));

    num = 0;
    charname = charnames;
    while(*charname) {
	charname++;
	if(num<256) {
	    if(*charname) encoding[num] = strdup(*charname);
	    else          encoding[num] = strdup(".notdef");
	}
	num++;
    }
    for(t=num;t<256;t++)
	encoding[t] = strdup(".notdef");
    
    //T1_ReencodeFont(nr, encoding);

    font->maxascii = num;
    font->numchars = num;
    
    font->style = (/*bold*/0?FONT_STYLE_BOLD:0) + (angle>0.05?FONT_STYLE_ITALIC:0);

    font->glyph = (SWFGLYPH*)rfx_calloc(num*sizeof(SWFGLYPH));
    font->glyph2ascii = (U16*)rfx_calloc(num*sizeof(U16));
    font->ascii2glyph = (int*)rfx_calloc(font->maxascii*sizeof(int));
    font->layout->ascent = (U16)(underline - bbox.lly);
    font->layout->descent = (U16)(bbox.ury - underline);
    font->layout->leading = (U16)(font->layout->ascent - 
	                     font->layout->descent -
			     (bbox.lly - bbox.ury));
    font->layout->bounds = (SRECT*)rfx_calloc(sizeof(SRECT)*num);
    font->layout->kerningcount = 0;
    font->layout->kerning = 0;
    font->glyphnames = rfx_calloc(num*sizeof(char*));
  
    num = 0;

    charname = charnames;
    for(c=0;c<font->numchars;c++) {
	drawer_t draw;
	SRECT bbox;
	T1_OUTLINE * outline;
	FPOINT pos,last;
	int firstx;
	
	outline = T1_GetCharOutline(nr, c, 100.0, 0);
	firstx = outline->dest.x/0xffff;

	pos.x = 0;
	pos.y = 0;
	last = pos;
	
	font->glyphnames[c] = strdup(*charname);

	if(c<font->maxascii)
	    font->ascii2glyph[c] = c;
	font->glyph2ascii[c] = c;
	
	swf_Shape01DrawerInit(&draw, 0);

	while(outline) {
	    pos.x += (outline->dest.x/(float)0xffff);
	    pos.y += (outline->dest.y/(float)0xffff);

	    if(outline->type == T1_PATHTYPE_MOVE) {
		draw.moveTo(&draw,&pos);
	    } else if(outline->type == T1_PATHTYPE_LINE) {
		draw.lineTo(&draw,&pos);
	    } else if(outline->type == T1_PATHTYPE_BEZIER) {
		T1_BEZIERSEGMENT*o2 = (T1_BEZIERSEGMENT*)outline;
		FPOINT b,c;
		b.x = o2->B.x/(float)0xffff+last.x;
		b.y = o2->B.y/(float)0xffff+last.y;
		c.x = o2->C.x/(float)0xffff+last.x;
		c.y = o2->C.y/(float)0xffff+last.y;
		draw_cubicTo(&draw,&b,&c,&pos);
	    } else {
		fprintf(stderr, "loadT1Font: unknown outline type:%d\n", outline->type);
	    }
	    last = pos;
	    outline = outline->link;
	}
	
	draw.finish(&draw);

	font->glyph[c].shape = swf_ShapeDrawerToShape(&draw);
	bbox = swf_ShapeDrawerGetBBox(&draw);
	draw.dealloc(&draw);
	    
	font->layout->bounds[c] = bbox;
	font->glyph[c].advance = bbox.xmax;
	if(!font->glyph[c].advance) {
	    font->glyph[c].advance = firstx;
	}
	charname++;
    }
    T1_DeleteFont(nr);

    for(t=0;t<256;t++)
	rfx_free(encoding[t]);
    return font;
}