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] Make the


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][gsoc-2022-chariri-3] [ftinspect] Make the waterfall config real-time and use start-end pair.
Date: Thu, 11 Aug 2022 15:32:46 +0000

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

Commits:

  • 5d9d55ed
    by Charlie Jiang at 2022-08-11T23:28:18+08:00
    [ftinspect] Make the waterfall config real-time and use start-end pair.
    
    It's more intuitive to use start-end instead of start-step, but it seems
    that the effect is not so good since we have a max granularity for the size
    value. Now the max precise is 0.25.
    
    There's now only one "Auto" checkbox and the auto status is tied for both
    values.
    
    * src/ftinspect/engine/stringrenderer.cpp,
      src/ftinspect/engine/stringrenderer.hpp:
      Change the step field to the end size field and add the calculation code.
    
    * src/ftinspect/panels/continuous.cpp, src/ftinspect/panels/continuous.hpp:
      Change the step boxes to end size, make the dialog modalless and update
      real-time.
    

4 changed files:

Changes:

  • src/ftinspect/engine/stringrenderer.cpp
    ... ... @@ -365,15 +365,34 @@ StringRenderer::render(int width,
    365 365
         auto ptHeight = 64 * 72 * height / engine_->dpi();
    
    366 366
         int step;
    
    367 367
     
    
    368
    -    if (waterfallStep_ <= 0)
    
    368
    +    if (waterfallStart_ <= 0)
    
    369
    +    {
    
    370
    +      // auto
    
    369 371
           step = (originalSize * originalSize / ptHeight + 64) & ~63;
    
    370
    -    else
    
    371
    -      step = static_cast<int>(waterfallStep_ * 64.0) & ~31;
    
    372
    -
    
    373
    -    if (waterfallStart_ < 0)
    
    374 372
           ptSize = ptSize - step * (ptSize / step); // modulo
    
    373
    +      ptSize += step;
    
    374
    +    }
    
    375 375
         else
    
    376
    +    {
    
    376 377
           ptSize = static_cast<int>(waterfallStart_ * 64.0) & ~31;
    
    378
    +      // we first get a ratio since height & ppem are near proportional...
    
    379
    +      // 64.0 is somewhat a magic reference number
    
    380
    +      engine_->setSizeByPoint(64.0);
    
    381
    +      engine_->reloadFont();
    
    382
    +      auto pixelActual = engine_->currentFontMetrics().height >> 6;
    
    383
    +
    
    384
    +      auto heightPt = height * 64.0 / pixelActual;
    
    385
    +
    
    386
    +      if (waterfallEnd_ < waterfallStart_)
    
    387
    +        waterfallEnd_ = waterfallStart_ + 1;
    
    388
    +
    
    389
    +      auto n = heightPt * 2 / (waterfallStart_ + waterfallEnd_);
    
    390
    +      auto stepTemp = (waterfallEnd_ - waterfallStart_) / (n + 1);
    
    391
    +      // rounding to 0.25
    
    392
    +      step = static_cast<int>(std::round(stepTemp * 4)) * 16 & ~15;
    
    393
    +      if (step == 0)
    
    394
    +        step = 16; // 0.25 pt
    
    395
    +    }
    
    377 396
     
    
    378 397
         int y = 0;
    
    379 398
         // no position param in "All Glyphs" mode
    
    ... ... @@ -382,7 +401,6 @@ StringRenderer::render(int width,
    382 401
     
    
    383 402
         while (true)
    
    384 403
         {
    
    385
    -      ptSize += step;
    
    386 404
           engine_->setSizeByPoint(ptSize / 64.0);
    
    387 405
           clearActive(true);
    
    388 406
           prepareRendering(); // set size/face for engine, so metrics are valid
    
    ... ... @@ -408,6 +426,10 @@ StringRenderer::render(int width,
    408 426
                                    width, height,
    
    409 427
                                    offset);
    
    410 428
           count = std::max(count, lcount);
    
    429
    +
    
    430
    +      if (step == 0)
    
    431
    +        break;
    
    432
    +      ptSize += step;
    
    411 433
         }
    
    412 434
         engine_->setSizeByPoint(originalSize / 64.0);
    
    413 435
     
    

  • src/ftinspect/engine/stringrenderer.hpp
    ... ... @@ -124,10 +124,10 @@ public:
    124 124
       void setVertical(bool vertical) { vertical_ = vertical; }
    
    125 125
       void setRotation(double rotation);
    
    126 126
       void setWaterfall(bool waterfall) { waterfall_ = waterfall; }
    
    127
    -  void setWaterfallParameters(double start, double step)
    
    127
    +  void setWaterfallParameters(double start, double end)
    
    128 128
       {
    
    129 129
         waterfallStart_ = start;
    
    130
    -    waterfallStep_ = step;
    
    130
    +    waterfallEnd_ = end;
    
    131 131
       }
    
    132 132
       void setPosition(double pos) { position_ = pos; }
    
    133 133
       void setLsbRsbDelta(bool enabled) { lsbRsbDeltaEnabled_ = enabled; }
    
    ... ... @@ -199,7 +199,7 @@ private:
    199 199
     
    
    200 200
       bool waterfall_ = false;
    
    201 201
       double waterfallStart_ = -1;
    
    202
    -  double waterfallStep_ = -1; // -1 = Auto
    
    202
    +  double waterfallEnd_ = -1; // -1 = Auto
    
    203 203
     
    
    204 204
       RenderCallback renderCallback_;
    
    205 205
       RenderImageCallback renderImageCallback_;
    

  • src/ftinspect/panels/continuous.cpp
    ... ... @@ -73,6 +73,10 @@ ContinuousTab::syncSettings()
    73 73
       // Not directly from the combo box
    
    74 74
       sr.setCharMapIndex(charMapIndex(), glyphLimitIndex_);
    
    75 75
     
    
    76
    +  if (sr.isWaterfall())
    
    77
    +    sr.setWaterfallParameters(wfConfigDialog_->startSize(),
    
    78
    +                              wfConfigDialog_->endSize());
    
    79
    +
    
    76 80
       //sr.setCentered(centered_->isChecked());
    
    77 81
     
    
    78 82
       canvas_->setFancyParams(xEmboldeningSpinBox_->value(),
    
    ... ... @@ -234,14 +238,7 @@ ContinuousTab::updateGlyphDetails(GlyphCacheEntry* ctxt,
    234 238
     void
    
    235 239
     ContinuousTab::openWaterfallConfig()
    
    236 240
     {
    
    237
    -  auto result = wfConfigDialog_->exec();
    
    238
    -  if (result != QDialog::Accepted)
    
    239
    -    return;
    
    240
    -
    
    241
    -  auto& sr = canvas_->stringRenderer();
    
    242
    -  sr.setWaterfallParameters(wfConfigDialog_->startSize(),
    
    243
    -                            wfConfigDialog_->stepSize());
    
    244
    -  repaintGlyph();
    
    241
    +  wfConfigDialog_->setVisible(true); // no `exec`: modalless
    
    245 242
     }
    
    246 243
     
    
    247 244
     
    
    ... ... @@ -432,6 +429,8 @@ ContinuousTab::createConnections()
    432 429
               canvas_, &GlyphContinuous::resetPositionDelta);
    
    433 430
       connect(waterfallConfigButton_, &QPushButton::clicked,
    
    434 431
               this, &ContinuousTab::openWaterfallConfig);
    
    432
    +  connect(wfConfigDialog_, &WaterfallConfigDialog::sizeUpdated,
    
    433
    +          this, &ContinuousTab::repaintGlyph);
    
    435 434
     
    
    436 435
       connect(xEmboldeningSpinBox_, 
    
    437 436
               QOverload<double>::of(&QDoubleSpinBox::valueChanged),
    
    ... ... @@ -504,7 +503,7 @@ ContinuousTab::formatIndex(int index)
    504 503
     WaterfallConfigDialog::WaterfallConfigDialog(QWidget* parent)
    
    505 504
     : QDialog(parent)
    
    506 505
     {
    
    507
    -  setModal(true);
    
    506
    +  setModal(false);
    
    508 507
       setWindowTitle(tr("Waterfall Config"));
    
    509 508
       setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
    
    510 509
     
    
    ... ... @@ -517,18 +516,18 @@ WaterfallConfigDialog::WaterfallConfigDialog(QWidget* parent)
    517 516
     double
    
    518 517
     WaterfallConfigDialog::startSize()
    
    519 518
     {
    
    520
    -  if (startAutoBox_->isChecked())
    
    519
    +  if (autoBox_->isChecked())
    
    521 520
         return -1.0;
    
    522 521
       return startSpinBox_->value();
    
    523 522
     }
    
    524 523
     
    
    525 524
     
    
    526 525
     double
    
    527
    -WaterfallConfigDialog::stepSize()
    
    526
    +WaterfallConfigDialog::endSize()
    
    528 527
     {
    
    529
    -  if (stepAutoBox_->isChecked())
    
    528
    +  if (autoBox_->isChecked())
    
    530 529
         return -1.0;
    
    531
    -  return stepSpinBox_->value();
    
    530
    +  return endSpinBox_->value();
    
    532 531
     }
    
    533 532
     
    
    534 533
     
    
    ... ... @@ -536,38 +535,27 @@ void
    536 535
     WaterfallConfigDialog::createLayout()
    
    537 536
     {
    
    538 537
       startLabel_ = new QLabel(tr("Start Size (pt):"), this);
    
    539
    -  stepLabel_ = new QLabel(tr("Size Step (pt):"), this);
    
    538
    +  endLabel_ = new QLabel(tr("End Size (pt):"), this);
    
    540 539
     
    
    541 540
       startSpinBox_ = new QDoubleSpinBox(this);
    
    542
    -  stepSpinBox_ = new QDoubleSpinBox(this);
    
    541
    +  endSpinBox_ = new QDoubleSpinBox(this);
    
    543 542
     
    
    544 543
       startSpinBox_->setSingleStep(0.5);
    
    545 544
       startSpinBox_->setMinimum(0.5);
    
    546 545
       startSpinBox_->setValue(1);
    
    547 546
     
    
    548
    -  stepSpinBox_->setSingleStep(0.5);
    
    549
    -  stepSpinBox_->setMinimum(0.5);
    
    550
    -  stepSpinBox_->setValue(1);
    
    551
    -
    
    552
    -  startAutoBox_ = new QCheckBox(tr("Auto"), this);
    
    553
    -  stepAutoBox_ = new QCheckBox(tr("Auto"), this);
    
    554
    -
    
    555
    -  okButton_ = new QPushButton(tr("OK"), this);
    
    556
    -  cancelButton_ = new QPushButton(tr("Cancel"), this);
    
    557
    -
    
    558
    -  buttonLayout_ = new QHBoxLayout;
    
    559
    -  buttonLayout_->addWidget(okButton_);
    
    560
    -  buttonLayout_->addWidget(cancelButton_);
    
    547
    +  endSpinBox_->setSingleStep(0.5);
    
    548
    +  endSpinBox_->setMinimum(0.5);
    
    549
    +  endSpinBox_->setValue(1);
    
    561 550
     
    
    551
    +  autoBox_ = new QCheckBox(tr("Auto"), this);
    
    552
    +  
    
    562 553
       layout_ = new QGridLayout;
    
    563
    -  auto startRow = gridLayout2ColAddWidget(layout_, startLabel_, startSpinBox_);
    
    564
    -  auto stepRow = gridLayout2ColAddWidget(layout_, stepLabel_, stepSpinBox_);
    
    565
    -  layout_->addWidget(startAutoBox_, startRow, 2);
    
    566
    -  layout_->addWidget(stepAutoBox_, stepRow, 2);
    
    567
    -  layout_->addLayout(buttonLayout_, layout_->rowCount(), 0, 1, 3);
    
    554
    +  gridLayout2ColAddWidget(layout_, autoBox_);
    
    555
    +  gridLayout2ColAddWidget(layout_, startLabel_, startSpinBox_);
    
    556
    +  gridLayout2ColAddWidget(layout_, endLabel_, endSpinBox_);
    
    568 557
     
    
    569
    -  startAutoBox_->setChecked(true);
    
    570
    -  stepAutoBox_->setChecked(true);
    
    558
    +  autoBox_->setChecked(true);
    
    571 559
     
    
    572 560
       setLayout(layout_);
    
    573 561
     }
    
    ... ... @@ -576,22 +564,24 @@ WaterfallConfigDialog::createLayout()
    576 564
     void
    
    577 565
     WaterfallConfigDialog::createConnections()
    
    578 566
     {
    
    579
    -  connect(startAutoBox_, &QCheckBox::clicked,
    
    580
    -          this, &WaterfallConfigDialog::checkAutoStatus);
    
    581
    -  connect(stepAutoBox_, &QCheckBox::clicked,
    
    567
    +  connect(autoBox_, &QCheckBox::clicked,
    
    582 568
               this, &WaterfallConfigDialog::checkAutoStatus);
    
    583
    -  connect(okButton_, &QPushButton::clicked,
    
    584
    -          this, &QDialog::accept);
    
    585
    -  connect(cancelButton_, &QPushButton::clicked,
    
    586
    -          this, &QDialog::reject);
    
    569
    +  connect(startSpinBox_, 
    
    570
    +          QOverload<double>::of(&QDoubleSpinBox::valueChanged),
    
    571
    +          this, &WaterfallConfigDialog::sizeUpdated);
    
    572
    +  connect(endSpinBox_, 
    
    573
    +          QOverload<double>::of(&QDoubleSpinBox::valueChanged),
    
    574
    +          this, &WaterfallConfigDialog::sizeUpdated);
    
    587 575
     }
    
    588 576
     
    
    589 577
     
    
    590 578
     void
    
    591 579
     WaterfallConfigDialog::checkAutoStatus()
    
    592 580
     {
    
    593
    -  startSpinBox_->setEnabled(!startAutoBox_->isChecked());
    
    594
    -  stepSpinBox_->setEnabled(!stepAutoBox_->isChecked());
    
    581
    +  startSpinBox_->setEnabled(!autoBox_->isChecked());
    
    582
    +  endSpinBox_->setEnabled(!autoBox_->isChecked());
    
    583
    +
    
    584
    +  emit sizeUpdated();
    
    595 585
     }
    
    596 586
     
    
    597 587
     
    

  • src/ftinspect/panels/continuous.hpp
    ... ... @@ -141,23 +141,21 @@ public:
    141 141
       WaterfallConfigDialog(QWidget* parent);
    
    142 142
     
    
    143 143
       double startSize();
    
    144
    -  double stepSize();
    
    144
    +  double endSize();
    
    145
    +
    
    146
    +signals:
    
    147
    +  void sizeUpdated();
    
    145 148
     
    
    146 149
     private:
    
    147 150
       QLabel* startLabel_;
    
    148
    -  QLabel* stepLabel_;
    
    151
    +  QLabel* endLabel_;
    
    149 152
     
    
    150 153
       QDoubleSpinBox* startSpinBox_;
    
    151
    -  QDoubleSpinBox* stepSpinBox_;
    
    152
    -
    
    153
    -  QCheckBox* startAutoBox_;
    
    154
    -  QCheckBox* stepAutoBox_;
    
    154
    +  QDoubleSpinBox* endSpinBox_;
    
    155 155
     
    
    156
    -  QPushButton* okButton_;
    
    157
    -  QPushButton* cancelButton_;
    
    156
    +  QCheckBox* autoBox_;
    
    158 157
     
    
    159 158
       QGridLayout* layout_;
    
    160
    -  QHBoxLayout* buttonLayout_;
    
    161 159
     
    
    162 160
       void createLayout();
    
    163 161
       void createConnections();
    


  • reply via email to

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