static DiaObject * fig_read_text(FILE *file, DiaContext *ctx) { GPtrArray *props = NULL; TextProperty *tprop; DiaObject *newobj = NULL; int sub_type; int color; int depth; int pen_style; int font; real font_size; real angle; int font_flags; real height; real length; int x, y; char *text_buf = NULL; char* old_locale; old_locale = setlocale(LC_NUMERIC, "C"); if (fscanf(file, " %d %d %d %d %d %lf %lf %d %lf %lf %d %d", &sub_type, &color, &depth, &pen_style, &font, &font_size, &angle, &font_flags, &height, &length, &x, &y) != 12) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't read text info.")); setlocale(LC_NUMERIC, old_locale); return NULL; } /* Skip one space exactly */ text_buf = fig_read_text_line(file); newobj = create_standard_text(x/FIG_UNIT, y/FIG_UNIT); if (newobj == NULL) goto exit; props = prop_list_from_descs(xfig_text_descs,pdtpp_true); tprop = g_ptr_array_index(props,0); tprop->text_data = g_strdup(text_buf); /*g_free(text_buf); */ tprop->attr.alignment = sub_type; tprop->attr.position.x = x/FIG_UNIT; tprop->attr.position.y = y/FIG_UNIT; if ((font_flags & 4) == 0) { switch (font) { case 0: tprop->attr.font = dia_font_new_from_legacy_name("Times-Roman"); break; case 1: tprop->attr.font = dia_font_new_from_legacy_name("Times-Roman"); break; case 2: tprop->attr.font = dia_font_new_from_legacy_name("Times-Bold"); break; case 3: tprop->attr.font = dia_font_new_from_legacy_name("Times-Italic"); break; case 4: tprop->attr.font = dia_font_new_from_legacy_name("Helvetica"); break; case 5: tprop->attr.font = dia_font_new_from_legacy_name("Courier"); break; default: dia_context_add_message(ctx, _("Can't find LaTeX font nr. %d, using sans"), font); tprop->attr.font = dia_font_new_from_legacy_name("Helvetica"); } } else { if (font == -1) { /* "Default font" - wazzat? */ tprop->attr.font = dia_font_new_from_legacy_name("Times-Roman"); } else if (font < 0 || font >= num_fig_fonts()) { dia_context_add_message(ctx, _("Can't find Postscript font nr. %d, using sans"), font); tprop->attr.font = dia_font_new_from_legacy_name("Helvetica"); } else { tprop->attr.font = dia_font_new_from_legacy_name(fig_fonts[font]); } } tprop->attr.height = font_size*2.54/72.0; tprop->attr.color = fig_color(color, ctx); newobj->ops->set_props(newobj, props); /* Depth field */ add_at_depth(newobj, depth, ctx); exit: setlocale(LC_NUMERIC, old_locale); if (text_buf != NULL) g_free(text_buf); if (props != NULL) prop_list_free(props); return newobj; }
/*! * \brief Draw a string to _Textobj * * To get objects more similar to what we had during export we * should probably use TextOutputDev. It reassembles strings * based on their position on the page. Or maybe Dia/cairo should * stop realigning single glyphs in it's output? * * \todo Check alignment options - it's just guessed yet. */ void DiaOutputDev::drawString(GfxState *state, GooString *s) { Color text_color = this->fill_color; int len = s->getLength(); DiaObject *obj; gchar *utf8 = NULL; DiaFont *font; // ignore empty strings if (len == 0) return; // get the font if (!state->getFont()) return; if (!(state->getFontSize() > 0.0)) return; font = (DiaFont *)g_hash_table_lookup (this->font_map, state->getFont()); // we have to decode the string data first { GfxFont *f = state->getFont(); char *p = s->getCString(); CharCode code; int j = 0, m, n; utf8 = g_new (gchar, len * 6 + 1); Unicode *u; int uLen; double dx, dy, ox, oy; while (len > 0) { n = f->getNextChar(p, len, &code, &u, &uLen, &dx, &dy, &ox, &oy); p += n; len -= n; m = g_unichar_to_utf8 (u[0], &utf8[j]); j += m; } utf8[j] = '\0'; } // check for invisible text -- this is used by Acrobat Capture if (state->getRender() == 3) text_color.alpha = 0.0; // not sure how state->getLineX() is related, it's 0 in my test cases double tx = state->getCurX(); double ty = state->getCurY(); int rot = state->getRotate(); if (rot == 0) obj = create_standard_text (tx * scale, page_height - ty * scale); else /* XXX: at least for rot==90 */ obj = create_standard_text (ty * scale, tx * scale); //not applyStyle (obj, TEXT); GPtrArray *plist = g_ptr_array_new (); // the "text" property is special, it must be initialized with text // attributes, too. So here it comes first to avoid overwriting // the other values with defaults. prop_list_add_text (plist, "text", utf8); prop_list_add_font (plist, "text_font", font); prop_list_add_text_colour (plist, &text_color); prop_list_add_enum (plist, "text_alignment", this->alignment); prop_list_add_fontsize (plist, "text_height", state->getTransformedFontSize() * scale / 0.8); obj->ops->set_props (obj, plist); prop_list_free (plist); g_free (utf8); addObject (obj); }