Ticket #10573: 0001-Server-side-support-for-BFont-IsFullAndHalfFixed.patch

File 0001-Server-side-support-for-BFont-IsFullAndHalfFixed.patch, 2.4 KB (added by jackburton, 10 years ago)

Tentative patch

  • src/servers/app/font/FontStyle.cpp

    From 09cdcbcfb0bee229d1302eab205eddf3a5bda52d Mon Sep 17 00:00:00 2001
    From: Stefano Ceccherini <stefano.ceccherini@gmail.com>
    Date: Fri, 21 Feb 2014 22:39:26 +0100
    Subject: [PATCH] Server side support for BFont::IsFullAndHalfFixed(). Check a
     range of charachters to see if they have the same width.
    
    ---
     src/servers/app/font/FontStyle.cpp | 23 ++++++++++++++++++++++-
     src/servers/app/font/FontStyle.h   |  3 ++-
     2 files changed, 24 insertions(+), 2 deletions(-)
    
    diff --git a/src/servers/app/font/FontStyle.cpp b/src/servers/app/font/FontStyle.cpp
    index 5719e60..137b38b 100644
    a b FontStyle::FontStyle(node_ref& nodeRef, const char* path, FT_Face face)  
    3737    fFamily(NULL),
    3838    fID(0),
    3939    fBounds(0, 0, 0, 0),
    40     fFace(_TranslateStyleToFace(face->style_name))
     40    fFace(_TranslateStyleToFace(face->style_name)),
     41    fFullAndHalfFixed(false)
    4142{
    4243    fName.Truncate(B_FONT_STYLE_LENGTH);
    4344        // make sure this style can be found using the Be API
    FontStyle::FontStyle(node_ref& nodeRef, const char* path, FT_Face face)  
    5051    // calculate it because height = ascending + descending + leading
    5152    fHeight.leading = (double)(face->height - face->ascender + face->descender)
    5253        / face->units_per_EM;
     54
     55    if (IsFixedWidth())
     56        return;
     57
     58    // manually check if all applicable chars are the same width
     59
     60    FT_Int32 loadFlags = FT_LOAD_NO_SCALE | FT_LOAD_TARGET_NORMAL;
     61    if (FT_Load_Char(face, (uint32)' ', loadFlags) != 0)
     62        return;
     63
     64    int firstWidth = face->glyph->advance.x;
     65    for (uint32 c = ' ' + 1; c <= 0x7e; c++) {
     66        if (FT_Load_Char(face, c, loadFlags) != 0)
     67            return;
     68
     69        if (face->glyph->advance.x != firstWidth)
     70            return;
     71    }
     72
     73    fFullAndHalfFixed = true;
    5374}
    5475
    5576
  • src/servers/app/font/FontStyle.h

    diff --git a/src/servers/app/font/FontStyle.h b/src/servers/app/font/FontStyle.h
    index b64542b..5103afa 100644
    a b class FontStyle : public ReferenceCounting, public Hashable {  
    8282    \return false (for now)
    8383*/
    8484        bool            IsFullAndHalfFixed() const
    85                             { return false; };
     85                            { return fFullAndHalfFixed; };
    8686
    8787/*!
    8888    \fn bool FontStyle::IsScalable(void)
    class FontStyle : public ReferenceCounting, public Hashable {  
    171171
    172172        font_height     fHeight;
    173173        uint16          fFace;
     174        bool            fFullAndHalfFixed;
    174175};
    175176
    176177#endif  // FONT_STYLE_H_