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-3] [ftinspect] Improve


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][gsoc-2022-chariri-3] [ftinspect] Improve bitmap displaying in the glyph details pane.
Date: Thu, 08 Sep 2022 17:11:55 +0000

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

Commits:

  • 21189cc9
    by Charlie Jiang at 2022-09-09T00:56:46+08:00
    [ftinspect] Improve bitmap displaying in the glyph details pane.
    
    * src/ftinspect/glyphcomponents/glyphbitmap.cpp:
      Add main border.
      Use blue lines as the ink box, thin black lines as the xy-axis and light
      gray lines as the EM-square.
      The origin is explicited handled, so no need to move the input rect down
      for ascender pixels. Negative y values are all supported.
    
    * src/ftinspect/panels/glyphdetails.cpp:
      No need to move the rect down for ascender pixels.
      No need to move the rect for non-spacing glyphs right.
    

2 changed files:

Changes:

  • src/ftinspect/glyphcomponents/glyphbitmap.cpp
    ... ... @@ -144,13 +144,25 @@ GlyphBitmapWidget::paintEvent(QPaintEvent* event)
    144 144
                       QPoint(std::max(rect_.right(), placeholderRect_.right()),
    
    145 145
                              std::max(rect_.bottom(), placeholderRect_.bottom())));
    
    146 146
       
    
    147
    -  double xScale = 0.9 * s.width() / br.right();
    
    148
    -  double yScale = 0.9 * s.height() / br.bottom();
    
    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;
    
    149 150
       auto scale = std::min(xScale, yScale);
    
    150 151
     
    
    151 152
       QPainter painter(this);
    
    152 153
       painter.fillRect(rect(), Qt::white);
    
    154
    +  painter.save(); // push before scaling
    
    153 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
    +  painter.drawRect(QRectF(rect_).adjusted(-scaledLineWidthHalf, 
    
    162
    +                                          -scaledLineWidthHalf,
    
    163
    +                                          scaledLineWidthHalf,
    
    164
    +                                          scaledLineWidthHalf));
    
    165
    +
    
    154 166
       painter.save(); // push before translating
    
    155 167
       painter.translate(rect_.topLeft());
    
    156 168
     
    
    ... ... @@ -159,23 +171,27 @@ GlyphBitmapWidget::paintEvent(QPaintEvent* event)
    159 171
       bitmapItem_->paint(&painter, &ogi, this);
    
    160 172
     
    
    161 173
       painter.restore(); // undo translating.
    
    162
    -  double scaledLineWidth = 4 / scale;
    
    163
    -  double scaledLineWidthHalf = scaledLineWidth / 2;
    
    164
    -  painter.setPen(QPen(Qt::black, scaledLineWidth));
    
    165
    -  painter.drawRect(QRectF(br).adjusted(scaledLineWidthHalf, 
    
    166
    -                                       scaledLineWidthHalf,
    
    167
    -                                       -scaledLineWidthHalf,
    
    168
    -                                       -scaledLineWidthHalf));
    
    169
    -  painter.setPen(QPen(Qt::red, scaledLineWidth));
    
    170
    -  painter.drawRect(QRectF(placeholderRect_).adjusted(scaledLineWidthHalf, 
    
    171
    -                                                     scaledLineWidthHalf,
    
    174
    +
    
    175
    +  scaledLineWidth /= 2;
    
    176
    +  scaledLineWidthHalf /= 2;
    
    177
    +  painter.setPen(QPen(Qt::lightGray, scaledLineWidth));
    
    178
    +  painter.drawRect(QRectF(placeholderRect_).adjusted(-scaledLineWidthHalf, 
    
    172 179
                                                          -scaledLineWidthHalf,
    
    173
    -                                                     -scaledLineWidthHalf));
    
    174
    -  painter.setPen(QPen(Qt::blue, scaledLineWidth));
    
    175
    -  painter.drawRect(QRectF(rect_).adjusted(scaledLineWidthHalf, 
    
    176
    -                                          scaledLineWidthHalf,
    
    177
    -                                          -scaledLineWidthHalf,
    
    178
    -                                          -scaledLineWidthHalf));
    
    180
    +                                                     scaledLineWidthHalf,
    
    181
    +                                                     scaledLineWidthHalf));
    
    182
    +
    
    183
    +  auto tfForAxis = painter.transform().inverted();
    
    184
    +  painter.setPen(QPen(Qt::black, scaledLineWidth / 2));
    
    185
    +  painter.drawLine(QPointF(tfForAxis.map(QPointF(0, 0)).x(), 0),
    
    186
    +                   QPointF(tfForAxis.map(QPointF(s.width(), 0)).x(), 0));
    
    187
    +  painter.drawLine(QPointF(0, tfForAxis.map(QPointF(0, 0)).y()),
    
    188
    +                   QPointF(0, tfForAxis.map(QPointF(0, s.height())).y()));
    
    189
    +
    
    190
    +  painter.restore(); // undo scaling.
    
    191
    +
    
    192
    +  // main border
    
    193
    +  painter.setPen(QPen(Qt::black, 4));
    
    194
    +  painter.drawRect(rect().adjusted(2, 2, -2, -2));
    
    179 195
     }
    
    180 196
     
    
    181 197
     
    

  • src/ftinspect/panels/glyphdetails.cpp
    ... ... @@ -53,13 +53,9 @@ GlyphDetails::updateGlyph(GlyphCacheEntry& ctxt, int charMapIndex)
    53 53
       
    
    54 54
       auto rect = ctxt.basePosition.translated(-(ctxt.penPos.x()),
    
    55 55
                                                -(ctxt.penPos.y()));
    
    56
    -  auto drawRect = rect;
    
    57
    -  drawRect.moveTop(drawRect.top() + (metrics.ascender >> 6));
    
    58
    -  if (!ctxt.advance.x)
    
    59
    -    drawRect.moveLeft(drawRect.left() + ctxt.nonSpacingPlaceholder);
    
    60 56
       bitmapWidget_->updateImage(
    
    61
    -      ctxt.image, drawRect,
    
    62
    -      QRect(0, 0, metrics.y_ppem, metrics.y_ppem));
    
    57
    +      ctxt.image, rect,
    
    58
    +      QRect(0, -metrics.y_ppem, metrics.y_ppem, metrics.y_ppem));
    
    63 59
     
    
    64 60
       // load glyphs in all units
    
    65 61
       dpi_ = engine_->dpi();
    


  • reply via email to

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