Commit ae95472b authored by XueShuming's avatar XueShuming
Browse files

update for text_helper

parent 2fbbae86
......@@ -147,22 +147,34 @@ typedef enum {
HISVG_TEXT_ALIGN_RIGHT
} HiSVGTextAlignment;
typedef struct _HiSVGTextContext HiSVGTextContext;
typedef struct _HiSVGTextContextLayout HiSVGTextContextLayout;
typedef struct _HiSVGTextContext {
struct _PangoContext* pango_ctx;
} HiSVGTextContext;
typedef struct _HiSVGTextContextLayout {
struct _PangoLayout* pango_layout;
HiSVGTextContext* context;
} HiSVGTextContextLayout;
typedef struct _HiSVGTextRectangle {
int x;
int y;
int width;
int height;
} HiSVGTextRectangle;
typedef struct _PangoFontDescription HiSVGFontDescription;
typedef struct _PangoRectangle HiSVGTextRectangle;
typedef struct _PangoLanguage HiSVGTextLanguage;
typedef struct _PangoAttrList HiSVGTextAttrList;
typedef struct _PangoAttribute HiSVGTextAttribute;
HiSVGTextContext* hisvg_create_text_context ();
void hisvg_text_context_set_resolution (HiSVGTextContext* context, double dpi);
HiSVGTextGravity hisvg_text_context_get_gravity (HiSVGTextContext* context);
void hisvg_text_context_set_language (HiSVGTextContext* context, const char* language);
void hisvg_text_context_set_base_dir (HiSVGTextContext* context, HiSVGTextDirection direction);
void hisvg_text_context_set_base_gravity (HiSVGTextContext* context, HiSVGTextGravity gravity);
HiSVGTextGravity hisvg_text_context_get_gravity (HiSVGTextContext* context);
HiSVGFontDescription* hisvg_text_context_get_font_description (HiSVGTextContext* context);
HiSVGTextContextLayout* hisvg_text_context_layout_new (HiSVGTextContext* context);
void hisvg_text_context_layout_get_size (HiSVGTextContextLayout* layout, int* width, int* height);
......@@ -171,8 +183,9 @@ void hisvg_text_context_layout_set_alignment (HiSVGTextContextLayout* layout, Hi
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);
HiSVGFontDescription* hisvg_text_context_get_font_description (HiSVGTextContext* context);
HiSVGFontDescription* hisvg_font_description_copy (const HiSVGFontDescription* desc);
void hisvg_font_description_set_family_static (HiSVGFontDescription* desc, const char* family);
void hisvg_font_description_set_style (HiSVGFontDescription* desc, HiSVGTextStyle style);
......@@ -184,14 +197,12 @@ 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, PangoAttribute* attr);
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);
HiSVGTextContext* hisvg_text_layout_get_context (HiSVGTextContextLayout* layout);
void hisvg_text_context_layout_get_extents (HiSVGTextContextLayout* layout, HiSVGTextRectangle* ink_rect, HiSVGTextRectangle* logical_rect);
double hisvg_text_gravity_to_rotation (HiSVGTextGravity gravity);
void hisvg_cairo_update_text_context (cairo_t* cr, HiSVGTextContext* context);
......
......@@ -397,7 +397,6 @@ hisvg_cairo_create_text_context (HiSVGDrawingCtx * ctx)
context = hisvg_create_text_context ();
hisvg_cairo_update_text_context (render->cr, context);
hisvg_text_context_set_resolution (context, ctx->dpi_y);
return context;
}
......
......@@ -48,17 +48,6 @@
#include <pango/pangocairo.h>
#include "hisvg-text-helper.h"
typedef struct _HiSVGTextContext {
struct _PangoContext* pango_ctx;
} HiSVGTextContext;
typedef struct _HiSVGTextContextLayout {
struct _PangoLayout* pango_layout;
HiSVGTextContext* context;
} HiSVGTextContextLayout;
typedef struct _PangoRectangle HiSVGTextRectangle;
HiSVGTextContext* hisvg_create_text_context ()
{
HiSVGTextContext* ctx = (HiSVGTextContext*) calloc(1, sizeof(HiSVGTextContext));
......@@ -71,11 +60,6 @@ void hisvg_text_context_set_resolution (HiSVGTextContext* context, double dpi)
pango_cairo_context_set_resolution (context->pango_ctx, dpi);
}
HiSVGTextGravity hisvg_text_context_get_gravity (HiSVGTextContext* context)
{
return pango_context_get_gravity (context->pango_ctx);
}
void hisvg_text_context_set_language (HiSVGTextContext* context, const char* language)
{
pango_context_set_language (context->pango_ctx, pango_language_from_string(language));
......@@ -91,6 +75,16 @@ void hisvg_text_context_set_base_gravity (HiSVGTextContext* context, HiSVGTextGr
pango_context_set_base_gravity (context->pango_ctx, gravity);
}
HiSVGTextGravity hisvg_text_context_get_gravity (HiSVGTextContext* context)
{
return pango_context_get_gravity (context->pango_ctx);
}
HiSVGFontDescription* hisvg_text_context_get_font_description (HiSVGTextContext* context)
{
return pango_context_get_font_description(context->pango_ctx);
}
HiSVGTextContextLayout* hisvg_text_context_layout_new (HiSVGTextContext* context)
{
HiSVGTextContextLayout* layout = (HiSVGTextContextLayout*)calloc(1, sizeof(HiSVGTextContextLayout));
......@@ -129,11 +123,6 @@ void hisvg_text_context_layout_set_font_description (HiSVGTextContextLayout* lay
pango_layout_set_font_description (layout->pango_layout, desc);
}
HiSVGFontDescription* hisvg_text_context_get_font_description (HiSVGTextContext* context)
{
return pango_context_get_font_description(context->pango_ctx);
}
HiSVGFontDescription* hisvg_font_description_copy (const HiSVGFontDescription* desc)
{
return pango_font_description_copy(desc);
......@@ -184,7 +173,7 @@ void hisvg_text_attr_list_unref (HiSVGTextAttrList* list)
pango_attr_list_unref (list);
}
void hisvg_text_attr_list_insert (HiSVGTextAttrList* list, PangoAttribute* attr)
void hisvg_text_attr_list_insert (HiSVGTextAttrList* list, HiSVGTextAttribute* attr)
{
pango_attr_list_insert (list, attr);
}
......@@ -206,13 +195,28 @@ HiSVGTextAttribute* hisvg_text_attr_letter_spacing_new (int letter_spacing)
HiSVGTextContext* hisvg_text_layout_get_context (HiSVGTextContextLayout* layout)
{
// return pango_layout_get_context(layout);
return layout->context;
}
void hisvg_text_context_layout_get_extents (HiSVGTextContextLayout* layout, HiSVGTextRectangle* ink_rect, HiSVGTextRectangle* logical_rect)
{
pango_layout_get_extents (layout->pango_layout, ink_rect, logical_rect);
PangoRectangle irect, lrect;
pango_layout_get_extents (layout->pango_layout, &irect, &lrect);
if (ink_rect)
{
ink_rect->x = irect.x;
ink_rect->y = irect.y;
ink_rect->width = irect.width;
ink_rect->height = irect.height;
}
if (logical_rect)
{
logical_rect->x = lrect.x;
logical_rect->y = lrect.y;
logical_rect->width = lrect.width;
logical_rect->height = lrect.height;
}
}
double hisvg_text_gravity_to_rotation (HiSVGTextGravity gravity)
......
......@@ -546,6 +546,9 @@ hisvg_text_create_layout (HiSVGDrawingCtx * ctx,
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);
if (state->lang)
hisvg_text_context_set_language (context, state->lang);
......
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