/** * Given a legacy name as stored until Dia-0.90 construct * a new DiaFont which is as similar as possible */ DiaFont* dia_font_new_from_legacy_name(const char* name) { /* do NOT translate anything here !!! */ DiaFont* retval; struct _legacy_font* found = NULL; real height = 1.0; int i; for (i = 0; i < G_N_ELEMENTS(legacy_fonts); i++) { if (!strcmp(name, legacy_fonts[i].oldname)) { found = &legacy_fonts[i]; break; } } if (found) { retval = dia_font_new (found->newname, found->style, height); retval->legacy_name = found->oldname; } else { /* We tried our best, let Pango complain */ retval = dia_font_new (name, DIA_FONT_WEIGHT_NORMAL, height); retval->legacy_name = NULL; } return retval; }
void updateFont(GfxState * state) { DiaFont *font; // without a font it wont make sense if (!state->getFont()) return; //FIXME: Dia is really unhappy about zero size fonts if (!(state->getFontSize() > 0.0)) return; GfxFont *f = state->getFont(); // instead of building the same font over and over again if (g_hash_table_lookup (this->font_map, f)) { ++font_map_hits; return; } DiaFontStyle style = (f->isSerif() ? DIA_FONT_SERIF : DIA_FONT_SANS) | (f->isItalic() ? DIA_FONT_ITALIC : DIA_FONT_NORMAL) // mapping all the font weights is just too much code for now ;) | (f->isBold () ? DIA_FONT_BOLD : DIA_FONT_WEIGHT_NORMAL); gchar *family = g_strdup (f->getFamily() ? f->getFamily()->getCString() : "sans"); double *mat = state->getTextMat(); // we are (not anymore) building the same font over and over again g_print ("Font 0x%08x: '%s' size=%g (* %g)\n", f, family, state->getFontSize(), mat[3]); // now try to make a fontname Dia/Pango can cope with // strip style postfix - we already have it extracted above char *pf; if ((pf = strstr (family, " Regular")) != NULL) *pf = 0; if ((pf = strstr (family, " Bold")) != NULL) *pf = 0; if ((pf = strstr (family, " Italic")) != NULL) *pf = 0; if ((pf = strstr (family, " Oblique")) != NULL) *pf = 0; if (mat[3] > 0.0) font = dia_font_new (family, style, state->getFontSize() * mat[3] * scale / 0.8); else // bug: in Gfx::opShowSpaceText() missing matrix setup? font = dia_font_new (family, style, state->getFontSize() / 0.8); g_hash_table_insert (this->font_map, f, font); g_free (family); }
/** Return the value of a font-type data node. This handles both the current * format (family and style) and the old format (name). * @param data The data node to read from. * @return The font value found in the node. If the node is not a * font node, an error message is displayed and NULL is returned. The * resulting value should be freed after use. */ DiaFont * data_font(DataNode data) { xmlChar *family; DiaFont *font; if (data_type(data)!=DATATYPE_FONT) { message_error("Taking font value of non-font node."); return NULL; } family = xmlGetProp(data, (const xmlChar *)"family"); /* always prefer the new format */ if (family) { DiaFontStyle style; char* style_name = (char *) xmlGetProp(data, (const xmlChar *)"style"); style = style_name ? atoi(style_name) : 0; font = dia_font_new ((char *)family, style, 1.0); if (family) free(family); if (style_name) xmlFree(style_name); } else { /* Legacy format support */ char *name = (char *)xmlGetProp(data, (const xmlChar *)"name"); font = dia_font_new_from_legacy_name(name); free(name); } return font; }
static DiaFont * _parse_font (xmlNodePtr node) { DiaFont *font = NULL; xmlChar *str; xmlChar *fam = xmlGetProp(node, (const xmlChar *)"family"); real size = _parse_real (node, "size"); if (size <= 0.0) size = 1.0; if (fam) font = dia_font_new ((const char *)fam, 0, size); if (!font) font = dia_font_new_from_style (DIA_FONT_SANS, size); str = xmlGetProp(node, (const xmlChar *)"weight"); if (str) { dia_font_set_weight_from_string (font, (const char*)str); xmlFree (str); } str = xmlGetProp(node, (const xmlChar *)"slant"); if (str) { dia_font_set_slant_from_string (font, (const char*)str); xmlFree (str); } if (fam) xmlFree (fam); return font; }
DiaFont* dia_font_copy(const DiaFont* font) { if (!font) return NULL; return dia_font_new(dia_font_get_family(font), dia_font_get_style(font), dia_font_get_height(font)); }