font metrics in cairo

Lynn Neir <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <F85A5683C7A97040826AE82D00E14CD00563A9E2@TK5EX14MBXC284.redmond.corp.microsoft.com>
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;
}

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.