Skip to content

Commit

Permalink
Deploying font_resolution somewhat further, but not using it for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koefferlein committed Aug 3, 2024
1 parent 40e360e commit 7470023
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/lay/lay/layMainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,7 @@ MainWindow::cm_print ()
scale_factor,
1,
1.0 / scale_factor,
1.0 / scale_factor,
tl::Color (QColor (Qt::white)), // foreground
tl::Color (QColor (Qt::black)), // background
tl::Color (QColor (Qt::black)), // active
Expand Down
6 changes: 3 additions & 3 deletions src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static void save_as2 (lay::LayoutViewBase *view, unsigned int index, const std::

static tl::PixelBuffer get_pixels_with_options (lay::LayoutViewBase *view, unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, const db::DBox &target_box)
{
return view->get_pixels_with_options (width, height, linewidth, oversampling, resolution, tl::Color (), tl::Color (), tl::Color (), target_box);
return view->get_pixels_with_options (width, height, linewidth, oversampling, resolution, resolution, tl::Color (), tl::Color (), tl::Color (), target_box);
}

static tl::BitmapBuffer get_pixels_with_options_mono (lay::LayoutViewBase *view, unsigned int width, unsigned int height, int linewidth, const db::DBox &target_box)
Expand All @@ -342,13 +342,13 @@ static tl::BitmapBuffer get_pixels_with_options_mono (lay::LayoutViewBase *view,

static void save_image_with_options (lay::LayoutViewBase *view, const std::string &fn, unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, const db::DBox &target_box, bool monochrome)
{
view->save_image_with_options (fn, width, height, linewidth, oversampling, resolution, tl::Color (), tl::Color (), tl::Color (), target_box, monochrome);
view->save_image_with_options (fn, width, height, linewidth, oversampling, resolution, resolution, tl::Color (), tl::Color (), tl::Color (), target_box, monochrome);
}

#if defined(HAVE_QT) && defined(HAVE_QTBINDINGS)
static QImage get_image_with_options (lay::LayoutViewBase *view, unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, const db::DBox &target_box, bool monochrome)
{
return view->get_image_with_options (width, height, linewidth, oversampling, resolution, tl::Color (), tl::Color (), tl::Color (), target_box, monochrome);
return view->get_image_with_options (width, height, linewidth, oversampling, resolution, resolution, tl::Color (), tl::Color (), tl::Color (), target_box, monochrome);
}

static QWidget *widget (lay::LayoutViewBase *view)
Expand Down
11 changes: 7 additions & 4 deletions src/laybasic/laybasic/layLayoutCanvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -769,18 +769,21 @@ class DetachedViewObjectCanvasMono
tl::PixelBuffer
LayoutCanvas::image (unsigned int width, unsigned int height)
{
return image_with_options (width, height, -1, -1, -1.0, tl::Color (), tl::Color (), tl::Color (), db::DBox ());
return image_with_options (width, height, -1, -1, -1.0, -1.0, tl::Color (), tl::Color (), tl::Color (), db::DBox ());
}

tl::PixelBuffer
LayoutCanvas::image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box)
LayoutCanvas::image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, double font_resolution, tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box)
{
if (oversampling <= 0) {
oversampling = m_oversampling;
}
if (resolution <= 0.0) {
resolution = 1.0 / oversampling;
}
if (font_resolution <= 0.0) {
font_resolution = resolution;
}
if (linewidth <= 0) {
linewidth = 1.0 / resolution + 0.5;
}
Expand All @@ -806,7 +809,7 @@ LayoutCanvas::image_with_options (unsigned int width, unsigned int height, int l

// provide canvas objects for the layout bitmaps and the foreground/background objects
BitmapRedrawThreadCanvas rd_canvas;
DetachedViewObjectCanvas vo_canvas (background, foreground, active, width * oversampling, height * oversampling, resolution, resolution, &img);
DetachedViewObjectCanvas vo_canvas (background, foreground, active, width * oversampling, height * oversampling, resolution, font_resolution, &img);

// compute the new viewport
db::DBox tb (target_box);
Expand All @@ -819,7 +822,7 @@ LayoutCanvas::image_with_options (unsigned int width, unsigned int height, int l
lay::RedrawThread redraw_thread (&rd_canvas, mp_view);

// render the layout
redraw_thread.start (0 /*synchronous*/, m_layers, vp, resolution, resolution, true);
redraw_thread.start (0 /*synchronous*/, m_layers, vp, resolution, font_resolution, true);
redraw_thread.stop (); // safety

// paint the background objects. It uses "img" to paint on.
Expand Down
2 changes: 1 addition & 1 deletion src/laybasic/laybasic/layLayoutCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class LAYBASIC_PUBLIC LayoutCanvas

tl::PixelBuffer screenshot ();
tl::PixelBuffer image (unsigned int width, unsigned int height);
tl::PixelBuffer image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box);
tl::PixelBuffer image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, double font_resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box);
tl::BitmapBuffer image_with_options_mono (unsigned int width, unsigned int height, int linewidth, tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box);

void update_image ();
Expand Down
12 changes: 6 additions & 6 deletions src/laybasic/laybasic/layLayoutViewBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2899,7 +2899,7 @@ LayoutViewBase::get_pixels (unsigned int width, unsigned int height)

#if defined(HAVE_QT)
QImage
LayoutViewBase::get_image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution,
LayoutViewBase::get_image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, double font_resolution,
tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box, bool monochrome)
{
tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (tr ("Get image")));
Expand All @@ -2909,20 +2909,20 @@ LayoutViewBase::get_image_with_options (unsigned int width, unsigned int height,
if (monochrome) {
return mp_canvas->image_with_options_mono (width, height, linewidth, background, foreground, active, target_box).to_image_copy ();
} else {
return mp_canvas->image_with_options (width, height, linewidth, oversampling, resolution, background, foreground, active, target_box).to_image_copy ();
return mp_canvas->image_with_options (width, height, linewidth, oversampling, resolution, font_resolution, background, foreground, active, target_box).to_image_copy ();
}
}
#endif

tl::PixelBuffer
LayoutViewBase::get_pixels_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution,
LayoutViewBase::get_pixels_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, double font_resolution,
tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box)
{
tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (tr ("Get image")));

refresh ();

return mp_canvas->image_with_options (width, height, linewidth, oversampling, resolution, background, foreground, active, target_box);
return mp_canvas->image_with_options (width, height, linewidth, oversampling, resolution, font_resolution, background, foreground, active, target_box);
}

tl::BitmapBuffer
Expand Down Expand Up @@ -2987,7 +2987,7 @@ LayoutViewBase::save_image (const std::string &, unsigned int, unsigned int)
#if defined(HAVE_QT) && !defined(PREFER_LIBPNG_FOR_SAVE)
void
LayoutViewBase::save_image_with_options (const std::string &fn,
unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution,
unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, double font_resolution,
tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box, bool monochrome)
{
tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (tr ("Save image")));
Expand All @@ -3007,7 +3007,7 @@ LayoutViewBase::save_image_with_options (const std::string &fn,
throw tl::Exception (tl::to_string (tr ("Unable to write screenshot to file: %s (%s)")), fn, tl::to_string (writer.errorString ()));
}
} else {
if (! writer.write (mp_canvas->image_with_options (width, height, linewidth, oversampling, resolution, background, foreground, active, target_box).to_image ())) {
if (! writer.write (mp_canvas->image_with_options (width, height, linewidth, oversampling, resolution, font_resolution, background, foreground, active, target_box).to_image ())) {
throw tl::Exception (tl::to_string (tr ("Unable to write screenshot to file: %s (%s)")), fn, tl::to_string (writer.errorString ()));
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/laybasic/laybasic/layLayoutViewBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -922,13 +922,14 @@ class LAYBASIC_PUBLIC LayoutViewBase :
* @param linewidth The width of a line in pixels (usually 1) or 0 for default
* @param oversampling The oversampling factor (1..3) or 0 for default
* @param resolution The resolution (pixel size compared to a screen pixel size, i.e 1/oversampling) or 0 for default
* @param font_resolution The resolution for rendering the "Default" font
* @param background The background color or tl::Color() for default
* @param foreground The foreground color or tl::Color() for default
* @param active The active color or tl::Color() for default
* @param target_box The box to draw or db::DBox() for default
* @param monochrome If true, monochrome images will be produced
*/
void save_image_with_options (const std::string &fn, unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box, bool monochrome);
void save_image_with_options (const std::string &fn, unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, double font_resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box, bool monochrome);

#if defined(HAVE_QT)
/**
Expand All @@ -951,13 +952,14 @@ class LAYBASIC_PUBLIC LayoutViewBase :
* @param linewidth The width of a line in pixels (usually 1) or 0 for default
* @param oversampling The oversampling factor (1..3) or 0 for default
* @param resolution The resolution (pixel size compared to a screen pixel size, i.e 1/oversampling) or 0 for default
* @param font_resolution The resolution for rendering the "Default" font
* @param background The background color or tl::Color() for default
* @param foreground The foreground color or tl::Color() for default
* @param active The active color or tl::Color() for default
* @param target_box The box to draw or db::DBox() for default
* @param monochrome If true, monochrome images will be produced
*/
QImage get_image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box, bool monochrome);
QImage get_image_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, double font_resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box, bool monochrome);
#endif

/**
Expand All @@ -968,12 +970,13 @@ class LAYBASIC_PUBLIC LayoutViewBase :
* @param linewidth The width of a line in pixels (usually 1) or 0 for default
* @param oversampling The oversampling factor (1..3) or 0 for default
* @param resolution The resolution (pixel size compared to a screen pixel size, i.e 1/oversampling) or 0 for default
* @param font_resolution The resolution for rendering the "Default" font
* @param background The background color or tl::Color() for default
* @param foreground The foreground color or tl::Color() for default
* @param active The active color or tl::Color() for default
* @param target_box The box to draw or db::DBox() for default
*/
tl::PixelBuffer get_pixels_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box);
tl::PixelBuffer get_pixels_with_options (unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, double font_resolution, tl::Color background, tl::Color foreground, tl::Color active_color, const db::DBox &target_box);

/**
* @brief Get the screen content as a monochrome tl::BitmapBuffer object with the given options
Expand Down
16 changes: 8 additions & 8 deletions src/layview/unit_tests/layLayoutViewTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TEST(1)
lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true);

QImage qimg;
qimg = lv.get_image_with_options (500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), false);
qimg = lv.get_image_with_options (500, 500, 1, 1, 1.0, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), false);

EXPECT_EQ (qimg.format () == QImage::Format_RGB32, true);

Expand All @@ -113,7 +113,7 @@ TEST(2)
lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true);

QImage qimg;
qimg = lv.get_image_with_options (500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), false);
qimg = lv.get_image_with_options (500, 500, 1, 1, 1.0, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), false);

EXPECT_EQ (qimg.format () == QImage::Format_RGB32, true);

Expand All @@ -136,7 +136,7 @@ TEST(3)
lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true);

QImage qimg;
qimg = lv.get_image_with_options (500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), true);
qimg = lv.get_image_with_options (500, 500, 1, 1, 1.0, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), true);

EXPECT_EQ (qimg.format () == QImage::Format_MonoLSB, true);

Expand Down Expand Up @@ -182,7 +182,7 @@ TEST(11)
lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true);

tl::PixelBuffer img;
img = lv.get_pixels_with_options (500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox ());
img = lv.get_pixels_with_options (500, 500, 1, 1, 1.0, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox ());

std::string tmp = tmp_file ("test.png");
{
Expand Down Expand Up @@ -210,7 +210,7 @@ TEST(12)
lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true);

tl::PixelBuffer img;
img = lv.get_pixels_with_options (500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox ());
img = lv.get_pixels_with_options (500, 500, 1, 1, 1.0, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox ());

std::string tmp = tmp_file ("test.png");
{
Expand Down Expand Up @@ -269,7 +269,7 @@ TEST(21)
lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true);

std::string tmp = tmp_file ("test.png");
lv.save_image_with_options (tmp, 500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), false);
lv.save_image_with_options (tmp, 500, 500, 1, 1, 1.0, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), false);

tl::PixelBuffer img;
{
Expand Down Expand Up @@ -297,7 +297,7 @@ TEST(22)
lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true);

std::string tmp = tmp_file ("test.png");
lv.save_image_with_options (tmp, 500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), false);
lv.save_image_with_options (tmp, 500, 500, 1, 1, 1.0, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), false);

tl::PixelBuffer img;
{
Expand Down Expand Up @@ -326,7 +326,7 @@ TEST(23)
lv.load_layout (tl::testsrc () + "/testdata/gds/t10.gds", true);

std::string tmp = tmp_file ("test.png");
lv.save_image_with_options (tmp, 500, 500, 1, 1, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), true);
lv.save_image_with_options (tmp, 500, 500, 1, 1, 1.0, 1.0, tl::Color (255, 255, 255), tl::Color (0, 0, 0), tl::Color (128, 128, 128), db::DBox (), true);

tl::BitmapBuffer img;
{
Expand Down

0 comments on commit 7470023

Please sign in to comment.