本文整理汇总了C++中WFont::sizeLength方法的典型用法代码示例。如果您正苦于以下问题:C++ WFont::sizeLength方法的具体用法?C++ WFont::sizeLength怎么用?C++ WFont::sizeLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WFont
的用法示例。
在下文中一共展示了WFont::sizeLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fontMetrics
WFontMetrics FontSupport::fontMetrics(const WFont& font)
{
PANGO_LOCK;
enabledFontFormats = enabledFontFormats_;
PangoFont *pangoFont = matchFont(font).pangoFont();
PangoFontMetrics *metrics = pango_font_get_metrics(pangoFont, nullptr);
double ascent
= pangoUnitsToDouble(pango_font_metrics_get_ascent(metrics));
double descent
= pangoUnitsToDouble(pango_font_metrics_get_descent(metrics));
double leading = (ascent + descent) - font.sizeLength(12).toPixels();
// ascent < leading is an odd thing. it happens with a font like
// Cursive.
if (ascent > leading)
ascent -= leading;
else
leading = 0;
WFontMetrics result(font, leading, ascent, descent);
pango_font_metrics_unref(metrics);
return result;
}
示例2: drawText
void FontSupport::drawText(const WFont& font, const WRectF& rect,
const WTransform& transform, Bitmap& bitmap,
WFlags<AlignmentFlag> flags,
const WString& text)
{
PANGO_LOCK;
enabledFontFormats = enabledFontFormats_;
PangoMatrix matrix;
matrix.xx = transform.m11();
matrix.xy = transform.m21();
matrix.yx = transform.m12();
matrix.yy = transform.m22();
matrix.x0 = transform.dx();
matrix.y0 = transform.dy();
std::string utf8 = text.toUTF8();
std::vector<PangoGlyphString *> glyphs;
int width;
pango_context_set_matrix(context_, &matrix);
/*
* Oh my god, somebody explain me why we need to do this...
*/
WFont f = font;
f.setSize(font.sizeLength().toPixels()
/ pango_matrix_get_font_scale_factor(&matrix));
GList *items = layoutText(f, utf8, glyphs, width);
pango_context_set_matrix(context_, nullptr);
AlignmentFlag hAlign = flags & AlignHorizontalMask;
/* FIXME handle bidi ! */
double x;
switch (hAlign) {
case AlignmentFlag::Left:
x = rect.left();
break;
case AlignmentFlag::Right:
x = rect.right() - pangoUnitsToDouble(width);
break;
case AlignmentFlag::Center:
x = rect.center().x() - pangoUnitsToDouble(width/2);
break;
default:
x = 0;
}
AlignmentFlag vAlign = flags & AlignVerticalMask;
PangoFont *pangoFont = matchFont(font).pangoFont();
PangoFontMetrics *metrics = pango_font_get_metrics(pangoFont, nullptr);
double ascent
= pangoUnitsToDouble(pango_font_metrics_get_ascent(metrics));
double descent
= pangoUnitsToDouble(pango_font_metrics_get_descent(metrics));
pango_font_metrics_unref(metrics);
double baseline = ascent;
double height = ascent + descent;
double y;
switch (vAlign) {
case AlignmentFlag::Top:
y = rect.top() + baseline;
break;
case AlignmentFlag::Middle:
y = rect.center().y() - height / 2 + baseline;
break;
case AlignmentFlag::Bottom:
y = rect.bottom() - height + baseline;
break;
default:
y = 0;
}
FT_Bitmap bmp;
bmp.buffer = bitmap.buffer();
bmp.width = bitmap.width();
bmp.rows = bitmap.height();
bmp.pitch = bitmap.pitch();
bmp.pixel_mode = FT_PIXEL_MODE_GRAY;
bmp.num_grays = 16; // ???
GList *elem;
unsigned i = 0;
for (elem = items; elem; elem = elem->next) {
PangoItem *item = (PangoItem *)elem->data;
PangoAnalysis *analysis = &item->analysis;
PangoGlyphString *gl = glyphs[i++];
//.........这里部分代码省略.........