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-final] [ftinspect] Impr


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][gsoc-2022-chariri-final] [ftinspect] Improve bitmap display in the glyph details pane.
Date: Thu, 08 Sep 2022 18:12:26 +0000

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

Commits:

  • 88fa0a5e
    by Charlie Jiang at 2022-09-09T02:09:48+08:00
    [ftinspect] Improve bitmap display in the glyph details pane.
    
    Now the ppem square is displayed as light gray, ink box as blue,
    xy-axis as thin black lines.
    Adding ppem square improves displaying of non-spacing glyphs.
    
    * src/ftinspect/panels/glyphdetails.cpp:
      Pass the ppem box to the `GlyphBitmap` widget.
    
    * src/ftinspect/glyphcomponents/glyphbitmap.cpp,
      src/ftinspect/glyphcomponents/glyphbitmap.hpp:
      Add a `placeholderRect` to store the ppem square info. Layout the glyph
      bitmap on the basis of the ppem square.
      Draw auxiliary lines on the canvas.
    

3 changed files:

Changes:

  • src/ftinspect/glyphcomponents/glyphbitmap.cpp
    ... ... @@ -107,14 +107,17 @@ GlyphBitmapWidget::~GlyphBitmapWidget()
    107 107
     
    
    108 108
     void
    
    109 109
     GlyphBitmapWidget::updateImage(QImage* image,
    
    110
    -                               QRect rect)
    
    110
    +                               QRect rect,
    
    111
    +                               QRect placeholderRect)
    
    111 112
     {
    
    112
    -  rect.moveTop(0);
    
    113
    -  rect.moveLeft(0);
    
    114
    -
    
    115 113
       delete bitmapItem_;
    
    116 114
       auto* copied = new QImage(image->copy());
    
    117
    -  bitmapItem_ = new GlyphBitmap(copied, rect);
    
    115
    +
    
    116
    +  rect_ = rect;
    
    117
    +  placeholderRect_ = placeholderRect;
    
    118
    +  auto zeroedRect = rect; // `GlyphBitmap` doesn't play well with offset
    
    119
    +  zeroedRect.moveTopLeft({ 0, 0 });
    
    120
    +  bitmapItem_ = new GlyphBitmap(copied, zeroedRect);
    
    118 121
     
    
    119 122
       repaint();
    
    120 123
     }
    
    ... ... @@ -135,24 +138,63 @@ GlyphBitmapWidget::paintEvent(QPaintEvent* event)
    135 138
       if (!bitmapItem_)
    
    136 139
         return;
    
    137 140
       auto s = size();
    
    138
    -  auto br = bitmapItem_->boundingRect();
    
    139
    -  double xScale = s.width() / br.width();
    
    140
    -  double yScale = s.height() / br.height();
    
    141
    +
    
    142
    +  auto br = QRect(QPoint(std::min(rect_.left(), placeholderRect_.left()),
    
    143
    +                         std::min(rect_.top(), placeholderRect_.top())),
    
    144
    +                  QPoint(std::max(rect_.right(), placeholderRect_.right()),
    
    145
    +                         std::max(rect_.bottom(), placeholderRect_.bottom())));
    
    146
    +  
    
    147
    +  double xScale = 0.9 * s.width() / br.width();
    
    148
    +  double yScale = 0.9 * s.height() / br.height();
    
    149
    +  auto margin = br.width() * 0.05;
    
    141 150
       auto scale = std::min(xScale, yScale);
    
    142 151
     
    
    143 152
       QPainter painter(this);
    
    144 153
       painter.fillRect(rect(), Qt::white);
    
    154
    +  painter.save(); // push before scaling
    
    145 155
       painter.scale(scale, scale);
    
    156
    +  painter.translate(-br.topLeft() + QPointF(margin, margin));
    
    157
    +
    
    158
    +  double scaledLineWidth = 4 / scale;
    
    159
    +  double scaledLineWidthHalf = scaledLineWidth / 2;
    
    160
    +  painter.setPen(QPen(Qt::blue, scaledLineWidth));
    
    161
    +  // Blue line: Ink box
    
    162
    +  painter.drawRect(QRectF(rect_).adjusted(-scaledLineWidthHalf,
    
    163
    +                                          -scaledLineWidthHalf,
    
    164
    +                                          scaledLineWidthHalf,
    
    165
    +                                          scaledLineWidthHalf));
    
    166
    +
    
    167
    +  painter.save(); // push before translating
    
    168
    +  painter.translate(rect_.topLeft());
    
    146 169
     
    
    147 170
       QStyleOptionGraphicsItem ogi;
    
    148 171
       ogi.exposedRect = br;
    
    149 172
       bitmapItem_->paint(&painter, &ogi, this);
    
    150 173
     
    
    151
    -  double scaledLineWidth = 4 / scale;
    
    152
    -  painter.setPen(QPen(Qt::black, scaledLineWidth));
    
    174
    +  painter.restore(); // undo translating.
    
    175
    +
    
    153 176
       scaledLineWidth /= 2;
    
    154
    -  painter.drawRect(br.adjusted(scaledLineWidth, scaledLineWidth,
    
    155
    -                               -scaledLineWidth, -scaledLineWidth));
    
    177
    +  scaledLineWidthHalf /= 2;
    
    178
    +  // Light gray line: EM box
    
    179
    +  painter.setPen(QPen(Qt::lightGray, scaledLineWidth));
    
    180
    +  painter.drawRect(QRectF(placeholderRect_).adjusted(-scaledLineWidthHalf, 
    
    181
    +                                                     -scaledLineWidthHalf,
    
    182
    +                                                     scaledLineWidthHalf,
    
    183
    +                                                     scaledLineWidthHalf));
    
    184
    +
    
    185
    +  auto tfForAxis = painter.transform().inverted();
    
    186
    +  painter.setPen(QPen(Qt::black, scaledLineWidth / 2));
    
    187
    +  // Thin black line: xy-axis
    
    188
    +  painter.drawLine(QPointF(tfForAxis.map(QPointF(0, 0)).x(), 0),
    
    189
    +                   QPointF(tfForAxis.map(QPointF(s.width(), 0)).x(), 0));
    
    190
    +  painter.drawLine(QPointF(0, tfForAxis.map(QPointF(0, 0)).y()),
    
    191
    +                   QPointF(0, tfForAxis.map(QPointF(0, s.height())).y()));
    
    192
    +
    
    193
    +  painter.restore(); // undo scaling.
    
    194
    +
    
    195
    +  // main border
    
    196
    +  painter.setPen(QPen(Qt::black, 4));
    
    197
    +  painter.drawRect(rect().adjusted(2, 2, -2, -2));
    
    156 198
     }
    
    157 199
     
    
    158 200
     
    

  • src/ftinspect/glyphcomponents/glyphbitmap.hpp
    ... ... @@ -48,8 +48,8 @@ class GlyphBitmapWidget
    48 48
     public:
    
    49 49
       GlyphBitmapWidget(QWidget* parent);
    
    50 50
       ~GlyphBitmapWidget() override;
    
    51
    -
    
    52
    -  void updateImage(QImage* image, QRect rect);
    
    51
    +  
    
    52
    +  void updateImage(QImage* image, QRect rect, QRect placeholderRect = {});
    
    53 53
       void releaseImage();
    
    54 54
     
    
    55 55
     signals:
    
    ... ... @@ -62,6 +62,8 @@ protected:
    62 62
     
    
    63 63
     private:
    
    64 64
       GlyphBitmap* bitmapItem_ = NULL;
    
    65
    +  QRect rect_ = {};
    
    66
    +  QRect placeholderRect_ = {};
    
    65 67
     };
    
    66 68
     
    
    67 69
     
    

  • src/ftinspect/panels/glyphdetails.cpp
    ... ... @@ -28,6 +28,7 @@ GlyphDetails::~GlyphDetails()
    28 28
     void
    
    29 29
     GlyphDetails::updateGlyph(GlyphCacheEntry& ctxt, int charMapIndex)
    
    30 30
     {
    
    31
    +  auto metrics = engine_->currentFontMetrics();
    
    31 32
       auto& cMaps = engine_->currentFontCharMaps();
    
    32 33
     
    
    33 34
       glyphIndex_ = ctxt.glyphIndex;
    
    ... ... @@ -49,10 +50,12 @@ GlyphDetails::updateGlyph(GlyphCacheEntry& ctxt, int charMapIndex)
    49 50
       if (glyphName.isEmpty())
    
    50 51
         glyphName = "(none)";
    
    51 52
       glyphNameLabel_->setText(glyphName);
    
    52
    -
    
    53
    +  
    
    53 54
       auto rect = ctxt.basePosition.translated(-(ctxt.penPos.x()),
    
    54 55
                                                -(ctxt.penPos.y()));
    
    55
    -  bitmapWidget_->updateImage(ctxt.image, rect);
    
    56
    +  bitmapWidget_->updateImage(
    
    57
    +      ctxt.image, rect,
    
    58
    +      QRect(0, -metrics.y_ppem, metrics.y_ppem, metrics.y_ppem));
    
    56 59
     
    
    57 60
       // load glyphs in all units
    
    58 61
       dpi_ = engine_->dpi();
    


  • reply via email to

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