[cairo] font metrics in cairo
Lynn Neir
lynn.neir at skype.net
Thu Mar 29 14:20:37 PDT 2012
Hello...
When getting font metrics (using win32 backend) regardless of hint metrics option, the values are always hinted. Anyone have any clues? Looks like in function _cairo_win32_scaled_font_set_metrics (cairo-win32-font.c) this might not be handled correctly? Any thoughts?
Here is sample code, always getting hinted ascent and descent values regardless of CAIRO_HINT_METRICS_OFF or CAIRO_HINT_METRICS_ON.
#include "stdafx.h"
#include <windows.h>
#include <string>
#include <iostream>
#include <cairo-win32.h>
int _tmain(int argc, _TCHAR* argv[])
{
HDC hdc = GetDC(0);
LOGFONT logfont;
std::wstring fontName(L"Arial");
memcpy(logfont.lfFaceName, fontName.data(), fontName.length() * sizeof(wchar_t));
logfont.lfFaceName[fontName.length()] = 0;
logfont.lfHeight = -256;
logfont.lfWidth = 0;
logfont.lfWeight = FW_NORMAL;
logfont.lfEscapement = 0;
logfont.lfOrientation = 0;
logfont.lfUnderline = false;
logfont.lfStrikeOut = false;
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
logfont.lfQuality = DEFAULT_QUALITY;
logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
HFONT font = CreateFontIndirect(&logfont);
if (!font)
return 0;
cairo_font_face_t* fontFace = cairo_win32_font_face_create_for_hfont(font);
int size = 8;
cairo_matrix_t sizeMatrix, ctm;
ctm.xx = ctm.xy = ctm.yx = ctm.yy = ctm.y0 = ctm.x0 = 0.0;
cairo_matrix_init_identity(&ctm);
cairo_matrix_init_scale(&sizeMatrix, size, size);
static cairo_font_options_t* fontOptions = 0;
fontOptions = cairo_font_options_create();
//cairo_font_options_set_hint_metrics(fontOptions, CAIRO_HINT_METRICS_ON);
cairo_font_options_set_hint_metrics(fontOptions, CAIRO_HINT_METRICS_OFF);
cairo_scaled_font_t* scaledFont = cairo_scaled_font_create(fontFace, &sizeMatrix, &ctm, fontOptions);
cairo_font_extents_t fontExtents;
cairo_scaled_font_extents(scaledFont, &fontExtents);
double ascent = fontExtents.ascent;
double descent = fontExtents.descent;
std::cout << "ascent = " << ascent << std::endl;
std::cout << "descent = " << descent << std::endl;
cairo_font_face_destroy(fontFace);
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20120329/ead826ea/attachment.html>
More information about the cairo
mailing list