freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype-demos][gsoc-2022-chariri-2] 3 commits: [ftinspec


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][gsoc-2022-chariri-2] 3 commits: [ftinspect] Fix Singular Grid View.
Date: Fri, 22 Jul 2022 00:10:54 +0000

Charlie Jiang pushed to branch gsoc-2022-chariri-2 at FreeType / FreeType Demo Programs

Commits:

  • 22616463
    by Charlie Jiang at 2022-07-21T14:52:42+08:00
    [ftinspect] Fix Singular Grid View.
    
    When drawing a `FT_BitmapGlyph`, sometimes the `bitmap->top` need to be
    negated while sometimes not, so add a argument to control this behavior.
    
    * src/ftinspect/engine/engine.cpp, src/ftinspect/engine/engine.hpp:
      Add `inverseRectY` arg to `Engine::convertGlyphToQImage`.
    
    * src/ftinspect/rendering/glyphbitmap.cpp: Negate Y coord.
    
    * src/ftinspect/rendering/glyphcontinuous.cpp: Don't negate Y coord.
    
  • 7aece3a7
    by Charlie Jiang at 2022-07-22T07:56:10+08:00
    * src/ftinspect/engine/engine.hpp: Fix ftinspect segfault.
    
    Always initialize fields in the constructor. The uninitialized `scaler_` is
    preventing the guard at `engine.cpp:339` from effecting.
    
  • 17c09dca
    by Charlie Jiang at 2022-07-22T08:05:03+08:00
    [ftinspect] Fix CharMap selector when the font file is symlink.
    
    When the font file is a symlink, the font will be periodically reloaded
    every 1s. When reloading, if the font's charmaps have no change, then the
    charmap selector shouldn't be re-populated, or it would be hard to change
    the current charmap.
    
    * src/ftinspect/panels/continuous.cpp: Add a guard to prevent unnecessary
      combobox repopulating.
    
    * src/ftinspect/engine/charmap.hpp: Add proper `operator==` for class
      `CharMapInfo`.
    

6 changed files:

Changes:

  • src/ftinspect/engine/charmap.hpp
    ... ... @@ -27,6 +27,21 @@ struct CharMapInfo
    27 27
       QString stringifyIndex(int code, int index);
    
    28 28
       QString stringifyIndexShort(int code);
    
    29 29
     
    
    30
    +
    
    31
    +  friend bool
    
    32
    +  operator==(const CharMapInfo& lhs, const CharMapInfo& rhs)
    
    33
    +  {
    
    34
    +    return lhs.index == rhs.index && lhs.encoding == rhs.encoding;
    
    35
    +  }
    
    36
    +
    
    37
    +
    
    38
    +  friend bool
    
    39
    +  operator!=(const CharMapInfo& lhs, const CharMapInfo& rhs)
    
    40
    +  {
    
    41
    +    return !(lhs == rhs);
    
    42
    +  }
    
    43
    +
    
    44
    +
    
    30 45
     private:
    
    31 46
       int computeMaxIndex();
    
    32 47
       static int maxIndexForFaceAndCharMap(FT_CharMap charMap, unsigned max);
    

  • src/ftinspect/engine/engine.cpp
    ... ... @@ -882,7 +882,9 @@ cleanup:
    882 882
     
    
    883 883
     
    
    884 884
     QImage*
    
    885
    -Engine::convertGlyphToQImage(FT_Glyph src, QRect* outRect)
    
    885
    +Engine::convertGlyphToQImage(FT_Glyph src,
    
    886
    +                             QRect* outRect,
    
    887
    +                             bool inverseRectY)
    
    886 888
     {
    
    887 889
       FT_BitmapGlyph bitmapGlyph;
    
    888 890
       bool ownBitmapGlyph
    
    ... ... @@ -895,7 +897,10 @@ Engine::convertGlyphToQImage(FT_Glyph src, QRect* outRect)
    895 897
       if (result && outRect)
    
    896 898
       {
    
    897 899
         outRect->setLeft(bitmapGlyph->left);
    
    898
    -    outRect->setTop(bitmapGlyph->top);
    
    900
    +    if (inverseRectY)
    
    901
    +      outRect->setTop(-bitmapGlyph->top);
    
    902
    +    else
    
    903
    +      outRect->setTop(bitmapGlyph->top);
    
    899 904
         outRect->setWidth(bitmapGlyph->bitmap.width);
    
    900 905
         outRect->setHeight(bitmapGlyph->bitmap.rows);
    
    901 906
       }
    
    ... ... @@ -908,7 +913,7 @@ Engine::convertGlyphToQImage(FT_Glyph src, QRect* outRect)
    908 913
     
    
    909 914
     
    
    910 915
     QPoint
    
    911
    -Engine::computeGlyphOffset(FT_Glyph glyph)
    
    916
    +Engine::computeGlyphOffset(FT_Glyph glyph, bool inverseY)
    
    912 917
     {
    
    913 918
       if (glyph->format == FT_GLYPH_FORMAT_OUTLINE)
    
    914 919
       {
    
    ... ... @@ -919,13 +924,17 @@ Engine::computeGlyphOffset(FT_Glyph glyph)
    919 924
         cbox.yMin &= ~63;
    
    920 925
         cbox.xMax = (cbox.xMax + 63) & ~63;
    
    921 926
         cbox.yMax = (cbox.yMax + 63) & ~63;
    
    927
    +    if (inverseY)
    
    928
    +      cbox.yMax = -cbox.yMax;
    
    922 929
         return { static_cast<int>(cbox.xMin) / 64,
    
    923 930
                    static_cast<int>(cbox.yMax / 64) };
    
    924 931
       }
    
    925 932
       if (glyph->format == FT_GLYPH_FORMAT_BITMAP)
    
    926 933
       {
    
    927 934
         auto bg = reinterpret_cast<FT_BitmapGlyph>(glyph);
    
    928
    -    return { bg->left, -bg->top };
    
    935
    +    if (inverseY)
    
    936
    +      return { bg->left, -bg->top };
    
    937
    +    return { bg->left, bg->top };
    
    929 938
       }
    
    930 939
     
    
    931 940
       return {};
    

  • src/ftinspect/engine/engine.hpp
    ... ... @@ -89,8 +89,10 @@ public:
    89 89
       bool convertGlyphToBitmapGlyph(FT_Glyph src, FT_Glyph* out);
    
    90 90
       FT_Bitmap convertBitmapTo8Bpp(FT_Bitmap* bitmap);
    
    91 91
       QImage* convertBitmapToQImage(FT_Bitmap* src);
    
    92
    -  QImage* convertGlyphToQImage(FT_Glyph src, QRect* outRect);
    
    93
    -  QPoint computeGlyphOffset(FT_Glyph glyph);
    
    92
    +  QImage* convertGlyphToQImage(FT_Glyph src, 
    
    93
    +                               QRect* outRect,
    
    94
    +                               bool inverseRectY);
    
    95
    +  QPoint computeGlyphOffset(FT_Glyph glyph, bool inverseY);
    
    94 96
     
    
    95 97
       // reload current triplet, but with updated settings, useful for updating
    
    96 98
       // `ftSize_` only
    
    ... ... @@ -191,7 +193,7 @@ private:
    191 193
       FTC_SBitCache sbitsCache_;
    
    192 194
       FTC_CMapCache cmapCache_;
    
    193 195
     
    
    194
    -  FTC_ScalerRec scaler_;
    
    196
    +  FTC_ScalerRec scaler_ = {};
    
    195 197
       FT_Size ftSize_;
    
    196 198
       FTC_ImageTypeRec imageType_;
    
    197 199
     
    

  • src/ftinspect/panels/continuous.cpp
    ... ... @@ -112,6 +112,11 @@ ContinuousTab::setGlyphBeginindex(int index)
    112 112
     void
    
    113 113
     ContinuousTab::setCharMaps(std::vector<CharMapInfo>& charMaps)
    
    114 114
     {
    
    115
    +  if (charMaps_ == charMaps)
    
    116
    +  {
    
    117
    +    charMaps_ = charMaps; // Still need to substitute because ptr may differ
    
    118
    +    return;
    
    119
    +  }
    
    115 120
       charMaps_ = charMaps;
    
    116 121
       int oldIndex = charMapSelector_->currentIndex();
    
    117 122
       unsigned oldEncoding = 0u;
    

  • src/ftinspect/rendering/glyphbitmap.cpp
    ... ... @@ -18,7 +18,7 @@ GlyphBitmap::GlyphBitmap(FT_Glyph glyph,
    18 18
                              Engine* engine)
    
    19 19
     {
    
    20 20
       QRect bRect;
    
    21
    -  image_ = engine->convertGlyphToQImage(glyph, &bRect);
    
    21
    +  image_ = engine->convertGlyphToQImage(glyph, &bRect, true);
    
    22 22
       boundingRect_ = bRect; // QRectF to QRect
    
    23 23
     }
    
    24 24
     
    

  • src/ftinspect/rendering/glyphcontinuous.cpp
    ... ... @@ -244,7 +244,7 @@ GlyphContinuous::drawSingleGlyph(QPainter* painter, FT_Glyph glyph)
    244 244
       }
    
    245 245
     
    
    246 246
       QRect rect;
    
    247
    -  QImage* image = engine_->convertGlyphToQImage(glyph, &rect);
    
    247
    +  QImage* image = engine_->convertGlyphToQImage(glyph, &rect, false);
    
    248 248
       rect.setTop(height() - rect.top());
    
    249 249
     
    
    250 250
       painter->drawImage(rect.topLeft(), *image);
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]