Commit 802492ee authored by XueShuming's avatar XueShuming
Browse files

update hisvg_text_context_layout_xxx function

parent 9d21c69d
......@@ -178,9 +178,6 @@ typedef struct _HiSVGTextRectangle {
int height;
} HiSVGTextRectangle;
typedef struct _PangoAttrList HiSVGTextAttrList;
typedef struct _PangoAttribute HiSVGTextAttribute;
HiSVGTextContext* hisvg_create_text_context ();
void hisvg_text_context_set_resolution (HiSVGTextContext* context, double dpi);
void hisvg_text_context_set_language (HiSVGTextContext* context, const char* language);
......@@ -188,15 +185,14 @@ void hisvg_text_context_set_base_dir (HiSVGTextContext* context, HiSVGTextDirect
void hisvg_text_context_set_base_gravity (HiSVGTextContext* context, HiSVGTextGravity gravity);
HiSVGTextGravity hisvg_text_context_get_gravity (HiSVGTextContext* context);
HiSVGTextContextLayout* hisvg_text_context_layout_new (HiSVGTextContext* context);
HiSVGTextContextLayout* hisvg_text_context_layout_create (HiSVGTextContext* context,
int letter_spacing, HiSVGTextAlignment alignment, const HiSVGFontDescription* desc,
int font_decoration, const char* text);
void hisvg_text_context_layout_get_size (HiSVGTextContextLayout* layout, int* width, int* height);
int hisvg_text_context_layout_get_baseline (HiSVGTextContextLayout* layout);
void hisvg_text_context_layout_set_alignment (HiSVGTextContextLayout* layout, HiSVGTextAlignment alignment);
void hisvg_text_context_layout_set_attributes (HiSVGTextContextLayout* layout, HiSVGTextAttrList* attrs);
void hisvg_text_context_layout_set_text (HiSVGTextContextLayout* layout, const char* text, int length);
void hisvg_text_context_layout_set_font_description (HiSVGTextContextLayout* layout, const HiSVGFontDescription* desc);
HiSVGTextContext* hisvg_text_layout_get_context (HiSVGTextContextLayout* layout);
void hisvg_text_context_layout_get_extents (HiSVGTextContextLayout* layout, HiSVGTextRectangle* ink_rect, HiSVGTextRectangle* logical_rect);
int hisvg_text_context_layout_get_baseline (HiSVGTextContextLayout* layout);
HiSVGFontDescription* hisvg_font_description_create (const char* type,
const char* family, HiSVGTextStyle style, HiSVGTextVariant variant,
......@@ -205,14 +201,6 @@ HiSVGFontDescription* hisvg_font_description_create (const char* type,
);
void hisvg_font_description_free (HiSVGFontDescription* desc);
HiSVGTextAttrList* hisvg_text_attr_list_new (void);
void hisvg_text_attr_list_unref (HiSVGTextAttrList* list);
void hisvg_text_attr_list_insert (HiSVGTextAttrList* list, HiSVGTextAttribute* attr);
HiSVGTextAttribute* hisvg_text_attr_strikethrough_new (gboolean strikethrough);
HiSVGTextAttribute* hisvg_text_attr_underline_new (PangoUnderline underline);
HiSVGTextAttribute* hisvg_text_attr_letter_spacing_new (int letter_spacing);
double hisvg_text_gravity_to_rotation (HiSVGTextGravity gravity);
void hisvg_cairo_update_text_context (cairo_t* cr, HiSVGTextContext* context);
......
......@@ -82,52 +82,70 @@ HiSVGTextGravity hisvg_text_context_get_gravity (HiSVGTextContext* context)
return pango_context_get_gravity (context->pango_ctx);
}
HiSVGTextContextLayout* hisvg_text_context_layout_new (HiSVGTextContext* context)
{
HiSVGTextContextLayout* layout = (HiSVGTextContextLayout*)calloc(1, sizeof(HiSVGTextContextLayout));
layout->pango_layout = pango_layout_new (context->pango_ctx);
layout->context = context;
return layout;
}
HiSVGTextContextLayout* hisvg_text_context_layout_create (HiSVGTextContext* context,
int letter_spacing, HiSVGTextAlignment alignment, const HiSVGFontDescription* desc,
int font_decor, const char* text)
{
PangoLayout* layout = pango_layout_new (context->pango_ctx);
HiSVGTextContextLayout* result = (HiSVGTextContextLayout*)calloc(1, sizeof(HiSVGTextContextLayout));
result->pango_layout = layout;
result->context = context;
PangoAttrList* attr_list;
PangoAttribute* attribute;
// set font description
PangoFontDescription* pdesc = pango_font_description_new();
pango_font_description_set_family_static(pdesc, desc->family);
pango_font_description_set_style(pdesc, desc->style);
pango_font_description_set_variant(pdesc, desc->variant);
pango_font_description_set_weight(pdesc, desc->weight);
pango_font_description_set_stretch(pdesc, desc->stretch);
pango_font_description_set_size(pdesc, desc->size);
pango_layout_set_font_description (layout, pdesc);
pango_font_description_free(pdesc);
void hisvg_text_context_layout_get_size (HiSVGTextContextLayout* layout, int* width, int* height)
{
pango_layout_get_size (layout->pango_layout, width, height);
}
attr_list = pango_attr_list_new ();
attribute = pango_attr_letter_spacing_new (letter_spacing);
attribute->start_index = 0;
attribute->end_index = G_MAXINT;
pango_attr_list_insert (attr_list, attribute);
if (text)
{
if (font_decor & TEXT_UNDERLINE) {
attribute = pango_attr_underline_new (HISVG_TEXT_UNDERLINE_SINGLE);
attribute->start_index = 0;
attribute->end_index = -1;
pango_attr_list_insert (attr_list, attribute);
}
if (font_decor & TEXT_STRIKE) {
attribute = pango_attr_strikethrough_new (TRUE);
attribute->start_index = 0;
attribute->end_index = -1;
pango_attr_list_insert (attr_list, attribute);
}
}
int hisvg_text_context_layout_get_baseline (HiSVGTextContextLayout* layout)
{
return pango_layout_get_baseline(layout->pango_layout);
}
pango_layout_set_attributes (layout, attr_list);
pango_attr_list_unref (attr_list);
void hisvg_text_context_layout_set_alignment (HiSVGTextContextLayout* layout, HiSVGTextAlignment alignment)
{
return pango_layout_set_alignment (layout->pango_layout, alignment);
}
if (text)
pango_layout_set_text (layout, text, -1);
else
pango_layout_set_text (layout, NULL, 0);
void hisvg_text_context_layout_set_attributes (HiSVGTextContextLayout* layout, HiSVGTextAttrList* attrs)
{
return pango_layout_set_attributes (layout->pango_layout, attrs);
pango_layout_set_alignment (layout, alignment);
return result;
}
void hisvg_text_context_layout_set_text (HiSVGTextContextLayout* layout, const char* text, int length)
void hisvg_text_context_layout_get_size (HiSVGTextContextLayout* layout, int* width, int* height)
{
return pango_layout_set_text (layout->pango_layout, text, length);
pango_layout_get_size (layout->pango_layout, width, height);
}
void hisvg_text_context_layout_set_font_description (HiSVGTextContextLayout* layout, const HiSVGFontDescription* desc)
int hisvg_text_context_layout_get_baseline (HiSVGTextContextLayout* layout)
{
PangoFontDescription* pdesc = pango_font_description_new();
pango_font_description_set_family_static(pdesc, desc->family);
pango_font_description_set_style(pdesc, desc->style);
pango_font_description_set_variant(pdesc, desc->variant);
pango_font_description_set_weight(pdesc, desc->weight);
pango_font_description_set_stretch(pdesc, desc->stretch);
pango_font_description_set_size(pdesc, desc->size);
pango_layout_set_font_description (layout->pango_layout, pdesc);
pango_font_description_free(pdesc);
return pango_layout_get_baseline(layout->pango_layout);
}
HiSVGFontDescription* hisvg_font_description_create (const char* type,
......@@ -155,36 +173,6 @@ void hisvg_font_description_free (HiSVGFontDescription* desc)
free(desc);
}
HiSVGTextAttrList* hisvg_text_attr_list_new (void)
{
return pango_attr_list_new();
}
void hisvg_text_attr_list_unref (HiSVGTextAttrList* list)
{
pango_attr_list_unref (list);
}
void hisvg_text_attr_list_insert (HiSVGTextAttrList* list, HiSVGTextAttribute* attr)
{
pango_attr_list_insert (list, attr);
}
HiSVGTextAttribute* hisvg_text_attr_strikethrough_new (gboolean strikethrough)
{
return pango_attr_strikethrough_new (strikethrough);
}
HiSVGTextAttribute* hisvg_text_attr_underline_new (PangoUnderline underline)
{
return pango_attr_underline_new (underline);
}
HiSVGTextAttribute* hisvg_text_attr_letter_spacing_new (int letter_spacing)
{
return pango_attr_letter_spacing_new (letter_spacing);
}
HiSVGTextContext* hisvg_text_layout_get_context (HiSVGTextContextLayout* layout)
{
return layout->context;
......
......@@ -543,8 +543,6 @@ hisvg_text_create_layout (HiSVGDrawingCtx * ctx,
{
HiSVGFontDescription *font_desc;
HiSVGTextContextLayout *layout;
HiSVGTextAttrList *attr_list;
HiSVGTextAttribute *attribute;
fprintf(stderr, "############################# %s:%d:%s create layout context =%p|dpi_y=%f\n", __FILE__, __LINE__, __func__, context, ctx->dpi_y);
hisvg_text_context_set_resolution (context, ctx->dpi_y);
......@@ -558,48 +556,20 @@ hisvg_text_create_layout (HiSVGDrawingCtx * ctx,
if (HISVG_TEXT_GRAVITY_IS_VERTICAL (state->text_gravity))
hisvg_text_context_set_base_gravity (context, state->text_gravity);
int font_size = _hisvg_css_normalize_font_size (state, ctx) *
HISVG_TEXT_SCALE / ctx->dpi_y * 72;
int font_size = _hisvg_css_normalize_font_size (state, ctx) * HISVG_TEXT_SCALE / ctx->dpi_y * 72;
font_desc = hisvg_font_description_create("*", state->font_family,
state->font_style, state->font_variant, state->font_weight,
state->font_stretch, font_size, 1);
layout = hisvg_text_context_layout_new (context);
hisvg_text_context_layout_set_font_description (layout, font_desc);
hisvg_font_description_free (font_desc);
attr_list = hisvg_text_attr_list_new ();
attribute = hisvg_text_attr_letter_spacing_new (_hisvg_css_normalize_length (&state->letter_spacing,
ctx, 'h') * HISVG_TEXT_SCALE);
attribute->start_index = 0;
attribute->end_index = G_MAXINT;
hisvg_text_attr_list_insert (attr_list, attribute);
if (state->has_font_decor && text) {
if (state->font_decor & TEXT_UNDERLINE) {
attribute = hisvg_text_attr_underline_new (HISVG_TEXT_UNDERLINE_SINGLE);
attribute->start_index = 0;
attribute->end_index = -1;
hisvg_text_attr_list_insert (attr_list, attribute);
}
if (state->font_decor & TEXT_STRIKE) {
attribute = hisvg_text_attr_strikethrough_new (TRUE);
attribute->start_index = 0;
attribute->end_index = -1;
hisvg_text_attr_list_insert (attr_list, attribute);
}
}
int letter_spacing = _hisvg_css_normalize_length (&state->letter_spacing,
ctx, 'h') * HISVG_TEXT_SCALE;
HiSVGTextAlignment alignment = (state->text_dir == HISVG_TEXT_DIRECTION_LTR) ?
HISVG_TEXT_ALIGN_LEFT : HISVG_TEXT_ALIGN_RIGHT;
layout = hisvg_text_context_layout_create (context,
letter_spacing, alignment, font_desc, state->font_decor, text);
hisvg_text_context_layout_set_attributes (layout, attr_list);
hisvg_text_attr_list_unref (attr_list);
if (text)
hisvg_text_context_layout_set_text (layout, text, -1);
else
hisvg_text_context_layout_set_text (layout, NULL, 0);
hisvg_text_context_layout_set_alignment (layout, (state->text_dir == HISVG_TEXT_DIRECTION_LTR) ?
HISVG_TEXT_ALIGN_LEFT : HISVG_TEXT_ALIGN_RIGHT);
hisvg_font_description_free (font_desc);
return layout;
}
......@@ -642,6 +612,7 @@ hisvg_text_render_text (HiSVGDrawingCtx * ctx, const char *text, gdouble * x, gd
context = ctx->render->create_text_context (ctx);
layout = hisvg_text_create_layout (ctx, state, text, context);
hisvg_text_context_layout_get_size (layout, &w, &h);
fprintf(stderr, "...............................................get size w=%d|h=%d\n", w, h);
baseline = hisvg_text_context_layout_get_baseline(layout);
offset = baseline / (double) HISVG_TEXT_SCALE;
offset += _hisvg_css_accumulate_baseline_shift (state, ctx);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment