Skip to content

Commit

Permalink
dpi scaling font and resizing in graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
qPCR4vir committed May 22, 2024
1 parent c0b6e42 commit 2c30869
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions source/paint/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @file nana/paint/graphics.cpp
*/
#include <algorithm>

#if defined(NANA_WINDOWS)
#include <windows.h>
#elif defined(NANA_X11)
Expand Down Expand Up @@ -273,12 +274,14 @@ namespace paint
void graphics::set_dpi(int dpi)
{
if (dpi == impl_->dpi) return;
auto sz = platform_abstraction::unscale_dpi(impl_->size, impl_->dpi);
impl_->dpi = dpi;
auto sz = this->size();
auto info = typeface().info();
graphics duplicate(std::move(*this));
impl_->dpi = dpi;
nana::paint::font ft{ info.value(), dpi };
typeface(ft);
make(sz);
make(sz); // this will scale the size to the dpi
bitblt(0, 0, duplicate);
}
int graphics::get_dpi() const
{
Expand All @@ -287,12 +290,17 @@ namespace paint
graphics::graphics(int dpi)
: impl_(new implementation{.dpi{dpi}, .scale{dpi/96.0f}})
{
//set_dpi(dpi);
auto info = typeface().info();
nana::paint::font ft{ info.value(), dpi };
typeface(ft);
}

graphics::graphics(const nana::size& sz, int dpi)
: impl_(new implementation{.dpi{dpi}, .scale{dpi/96.0f}})
{
auto info = typeface().info();
nana::paint::font ft{ info.value(), dpi };
typeface(ft);
make(sz);
}

Expand Down

0 comments on commit 2c30869

Please sign in to comment.