Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Area Text::box(const Area &area, double &font_size, Alignment &align) const
- {
- PangoFontMap *font_map = pango_ft2_font_map_new();
- PangoContext *ctx = pango_font_map_create_context(font_map);
- PangoFontDescription *font_desc = pango_font_description_new();
- pango_font_description_set_family(font_desc, "Font");
- pango_font_description_set_style(font_desc, PANGO_STYLE_NORMAL);
- pango_font_description_set_variant(font_desc, PANGO_VARIANT_NORMAL);
- pango_font_description_set_weight (font_desc, PANGO_WEIGHT_NORMAL);
- pango_font_description_set_stretch(font_desc, PANGO_STRETCH_NORMAL);
- pango_font_description_set_size(font_desc, 100 * PANGO_SCALE);
- pango_context_set_font_description(ctx, font_desc);
- PangoLayout *layout = pango_layout_new(ctx);
- pango_layout_set_text(layout, m_text.c_str(), m_text.size());
- pango_layout_set_indent(layout, 0);
- int width, height;
- pango_layout_get_pixel_size(layout, &width, &height);
- g_object_unref(layout);
- double scale;
- Alignment area_align, text_align;
- if (area.width() >= area.height())
- {
- // area is horizontal dimensioned
- scale = area.width();
- area_align = Alignment::HORIZONTAL;
- } else
- {
- // area is vertically dimensioned
- scale = area.height();
- area_align = Alignment::VERTICAL;
- }
- if (width >= height)
- {
- // text box is horizontal dimensioned
- scale /= width;
- text_align = Alignment::HORIZONTAL;
- } else
- {
- // text box is vertically dimensioned
- scale /= height;
- text_align = Alignment::VERTICAL;
- }
- width *= scale;
- height *= scale;
- if (area_align == text_align)
- align = HORIZONTAL;
- else
- align = VERTICAL;
- Area result;
- result.begin() = area.begin();
- result.end() = area.begin() + Pixel(width, height);
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement