Example #1
0
static void
set_font(DiaRenderer *self, DiaFont *font, real height)
{
  DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
  /* pango/cairo wants the font size, not the (line-) height */
  real size = dia_font_get_size (font) * (height / dia_font_get_height (font));

  PangoFontDescription *pfd = pango_font_description_copy (dia_font_get_description (font));
  DIAG_NOTE(g_message("set_font %f %s", height, dia_font_get_family(font)));

#ifdef HAVE_PANGOCAIRO_H
  /* select font and size */
  pango_font_description_set_absolute_size (pfd, (int)(size * PANGO_SCALE));
  pango_layout_set_font_description (renderer->layout, pfd);
  pango_font_description_free (pfd);
#else
  if (renderer->cr) {
    DiaFontStyle style = dia_font_get_style (font);
    const char *family_name = dia_font_get_family(font);

    cairo_select_font_face (
        renderer->cr,
        family_name,
        DIA_FONT_STYLE_GET_SLANT(style) == DIA_FONT_NORMAL ? CAIRO_FONT_SLANT_NORMAL : CAIRO_FONT_SLANT_ITALIC,
        DIA_FONT_STYLE_GET_WEIGHT(style) < DIA_FONT_MEDIUM ? CAIRO_FONT_WEIGHT_NORMAL : CAIRO_FONT_WEIGHT_BOLD); 
    cairo_set_font_size (renderer->cr, size);

    DIAG_STATE(renderer->cr)
  }
Example #2
0
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));
}
Example #3
0
PangoLayout*
dia_font_build_layout(const char* string, DiaFont* font, real height)
{
  PangoLayout* layout;
  PangoAttrList* list;
  PangoAttribute* attr;
  guint length;
  PangoFontDescription *pfd;
  real factor;

  layout = pango_layout_new(dia_font_get_context());

  length = string ? strlen(string) : 0;
  pango_layout_set_text(layout, string, length);

  list = pango_attr_list_new();

  pfd = pango_font_description_copy (font->pfd);
  /* account for difference between size and height as well as between font height and given one */
  factor = dia_font_get_size(font) / dia_font_get_height (font);
  pango_font_description_set_absolute_size (pfd, dcm_to_pdu (height) * factor);
  attr = pango_attr_font_desc_new(pfd);
  pango_font_description_free (pfd);

  attr->start_index = 0;
  attr->end_index = length;
  pango_attr_list_insert(list,attr); /* eats attr */

  pango_layout_set_attributes(layout,list);
  pango_attr_list_unref(list);

  pango_layout_set_indent(layout,0);
  pango_layout_set_justify(layout,FALSE);
  pango_layout_set_alignment(layout,PANGO_ALIGN_LEFT);

  return layout;
}
Example #4
0
static void
set_font(DiaRenderer *self, DiaFont *font, real height)
{
    WmfRenderer *renderer = WMF_RENDERER (self);

    W32::LPCTSTR sFace;
    W32::DWORD dwItalic = 0;
    W32::DWORD dwWeight = FW_DONTCARE;
    DiaFontStyle style = dia_font_get_style(font);
    real font_size = dia_font_get_size (font) * (height / dia_font_get_height (font));


    DIAG_NOTE(renderer, "set_font %s %f\n", 
              dia_font_get_family (font), height);
    if (renderer->hFont) {
	W32::DeleteObject(renderer->hFont);
	renderer->hFont = NULL;
    }
    if (renderer->pango_context) {
        g_object_unref (renderer->pango_context);
	renderer->pango_context = NULL;
    }
    
    if (renderer->use_pango) {
#ifdef __PANGOWIN32_H__ /* with the pangowin32 backend there is a better way */
	if (!renderer->pango_context)
	    renderer->pango_context = pango_win32_get_context ();

	PangoFont* pf = pango_context_load_font (renderer->pango_context, dia_font_get_description (font));
	if (pf)
	{
	    W32::LOGFONT* lf = pango_win32_font_logfont (pf);
	    /* .93 : sligthly smaller looks much better */
	    lf->lfHeight = -SC(height*.93);
	    lf->lfHeight = -SC(font_size);
	    renderer->hFont = (W32::HFONT)W32::CreateFontIndirect (lf);
	    g_free (lf);
	    g_object_unref (pf);
	}
	else
	{
	    gchar *desc = pango_font_description_to_string (dia_font_get_description (font));
	    dia_context_add_message(renderer->ctx, _("Cannot render unknown font:\n%s"), desc);
	    g_free (desc);
	}
#else
	g_assert_not_reached();
#endif
    } else {
	sFace = dia_font_get_family (font);
	dwItalic = DIA_FONT_STYLE_GET_SLANT(style) != DIA_FONT_NORMAL;

	/* although there is a known algorithm avoid it for cleanness */
	switch (DIA_FONT_STYLE_GET_WEIGHT(style)) {
	case DIA_FONT_ULTRALIGHT    : dwWeight = FW_ULTRALIGHT; break;
	case DIA_FONT_LIGHT         : dwWeight = FW_LIGHT; break;
	case DIA_FONT_MEDIUM        : dwWeight = FW_MEDIUM; break;
	case DIA_FONT_DEMIBOLD      : dwWeight = FW_DEMIBOLD; break;
	case DIA_FONT_BOLD          : dwWeight = FW_BOLD; break;
	case DIA_FONT_ULTRABOLD     : dwWeight = FW_ULTRABOLD; break;
	case DIA_FONT_HEAVY         : dwWeight = FW_HEAVY; break;
	default : dwWeight = FW_NORMAL; break;
	}
	//Hack to get BYTE out of namespace W32
#       ifndef BYTE
#       define BYTE unsigned char
#       endif

	renderer->hFont = (W32::HFONT)W32::CreateFont( 
		- SC (font_size),  // logical height of font 
		0,		// logical average character width 
		0,		// angle of escapement
		0,		// base-line orientation angle 
		dwWeight,	// font weight
		dwItalic,	// italic attribute flag
		0,		// underline attribute flag
		0,		// strikeout attribute flag
		DEFAULT_CHARSET,	// character set identifier 
		OUT_TT_PRECIS, 	// output precision 
		CLIP_DEFAULT_PRECIS,	// clipping precision
		PROOF_QUALITY,		// output quality 
		DEFAULT_PITCH,		// pitch and family
		sFace);		// pointer to typeface name string
    }
}
Example #5
0
static void
node_set_text_style (xmlNodePtr      node,
                     DiaSvgRenderer *renderer,
		     const DiaFont  *font,
		     real            font_height,
                     Alignment       alignment,
		     Color          *colour)
{
  char *style, *tmp;
  real saved_width;
  gchar d_buf[G_ASCII_DTOSTR_BUF_SIZE];
  DiaSvgRendererClass *svg_renderer_class = DIA_SVG_RENDERER_GET_CLASS (renderer);
  /* SVG font-size is the (line-) height, from SVG Spec:
   * ... property refers to the size of the font from baseline to baseline when multiple lines of text are set ...
  so we should be able to use font_height directly instead of:
   */
  real font_size = dia_font_get_size (font) * (font_height / dia_font_get_height (font));
  /* ... but at least Inkscape and Firefox would produce the wrong font-size */
  const gchar *family = dia_font_get_family(font);

  saved_width = renderer->linewidth;
  renderer->linewidth = 0.001;
  style = (char*)svg_renderer_class->get_fill_style(renderer, colour);
  /* return value must not be freed */
  renderer->linewidth = saved_width;
  /* This is going to break for non-LTR texts, as SVG thinks 'start' is
   * 'right' for those.
   */
  switch (alignment) {
  case ALIGN_LEFT:
    style = g_strconcat(style, ";text-anchor:start", NULL);
    break;
  case ALIGN_CENTER:
    style = g_strconcat(style, ";text-anchor:middle", NULL);
    break;
  case ALIGN_RIGHT:
    style = g_strconcat(style, ";text-anchor:end", NULL);
    break;
  }
#if 0 /* would need a unit according to https://bugzilla.mozilla.org/show_bug.cgi?id=707071#c4 */
  tmp = g_strdup_printf("%s;font-size:%s", style,
			dia_svg_dtostr(d_buf, font_size) );
  g_free (style);
  style = tmp;
#else
  /* font-size as attribute can work like the other length w/o unit */
  dia_svg_dtostr(d_buf, font_size);
  xmlSetProp(node, (const xmlChar *)"font-size", (xmlChar *) d_buf);
#endif

  if (font) {
     tmp = g_strdup_printf("%s;font-family:%s;font-style:%s;"
                           "font-weight:%s",style,
                           strcmp(family, "sans") == 0 ? "sans-serif" : family,
                           dia_font_get_slant_string(font),
                           dia_font_get_weight_string(font));
     g_free(style);
     style = tmp;
  }

  /* have to do something about fonts here ... */

  xmlSetProp(node, (xmlChar *)"style", (xmlChar *)style);
  g_free(style);
}