Skip to content

Commit

Permalink
HiDPI support implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
virxkane committed Jun 17, 2022
1 parent 4d12141 commit a9a64fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")

# Find the Qt5 libraries
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core 5.14 REQUIRED)
find_package(Qt5Gui 5.14 REQUIRED)
find_package(Qt5Widgets 5.14 REQUIRED)

option(USE_HARFBUZZ "Use HarfBuzz for text shaping" ON)
option(BUILD_TESTS "Build test programs" OFF)
Expand Down
4 changes: 4 additions & 0 deletions src/lowlevel_textrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "fc-lang-data.h"

#include <QtGui/QPainter>
#include <QtGui/QScreen>

#include <QtCore/QDebug>

Expand Down Expand Up @@ -139,6 +140,8 @@ bool GLowLevelTextRender::renderText(const QString& text)
bool GLowLevelTextRender::renderText()
{
QSize sz = size();
qreal dpr = screen()->devicePixelRatio();
sz *= dpr;
if (sz.width() < 100 || sz.height() < 100)
return false;
if (!m_d->freetypeIsInited())
Expand All @@ -158,6 +161,7 @@ bool GLowLevelTextRender::renderText()
if (!m_offscreen)
{
m_offscreen = new QImage(sz.width(), sz.height(), QImage::Format_RGB32);
m_offscreen->setDevicePixelRatio(dpr);
}
m_offscreen->fill(m_backgroundColor);

Expand Down
5 changes: 5 additions & 0 deletions src/mainwnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ui_mainwnd.h"

#include <QtGui/QShowEvent>
#include <QtGui/QScreen>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QCheckBox>

Expand All @@ -41,6 +42,10 @@ GMainWindow::GMainWindow(QWidget *parent)
ui->fontLineEdit->setText("c:/Windows/Fonts/NotoSerif-Regular.ttf");
#endif

qreal dpr = screen()->devicePixelRatio();
ui->fontSizeBox->setValue(ui->fontSizeBox->value()*dpr);
ui->fontSizeBox->setMaximum(ui->fontSizeBox->maximum()*dpr);

onFontChanged();
}

Expand Down

0 comments on commit a9a64fc

Please sign in to comment.