Skip to content

Commit

Permalink
Merge pull request #1822 from KLayout/feature/issue-1819
Browse files Browse the repository at this point in the history
Feature/issue 1819
  • Loading branch information
klayoutmatthias authored Aug 10, 2024
2 parents bccc421 + aada342 commit ea6ffb9
Show file tree
Hide file tree
Showing 36 changed files with 383 additions and 235 deletions.
1 change: 1 addition & 0 deletions src/lay/lay/layMainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,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
23 changes: 12 additions & 11 deletions src/laybasic/laybasic/layBitmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ Bitmap::Bitmap ()
{
init (0, 0);
m_resolution = 1.0;
m_font_resolution = 1.0;
}

Bitmap::Bitmap (unsigned int w, unsigned int h, double r)
Bitmap::Bitmap (unsigned int w, unsigned int h, double r, double rf)
: m_empty_scanline (0)
{
init (w, h);
m_resolution = r;
m_font_resolution = rf;
}

Bitmap::Bitmap (const Bitmap &d)
Expand All @@ -60,6 +62,7 @@ Bitmap::operator= (const Bitmap &d)
}

m_resolution = d.m_resolution;
m_font_resolution = d.m_font_resolution;

for (unsigned int i = 0; i < m_height; ++i) {
if (! d.m_scanlines.empty () && d.m_scanlines [i] != 0) {
Expand Down Expand Up @@ -290,16 +293,14 @@ Bitmap::fill_pattern (int y, int x, const uint32_t *pp, unsigned int stride, uns

while (n > 0 && y >= 0) {

for (unsigned int s = 0; s < stride; ++s) {
for (unsigned int s = 0; s < stride; ++s, pp++) {

int x1 = x + s * 32;

uint32_t p = *pp++;
uint32_t p = *pp;

if (x1 < 0) {
if (x1 <= -32) {
return;
}
int x1 = x + s * 32;
if (x1 <= -32 || x1 >= m_width) {
continue;
} else if (x1 < 0) {
p >>= (unsigned int)-x1;
x1 = 0;
}
Expand Down Expand Up @@ -796,7 +797,7 @@ Bitmap::render_text (const lay::RenderText &text)
{
if (text.font == db::DefaultFont) {

const lay::FixedFont &ff = lay::FixedFont::get_font (m_resolution);
const lay::FixedFont &ff = lay::FixedFont::get_font (m_font_resolution);

// count the lines and max. characters per line

Expand Down Expand Up @@ -877,7 +878,7 @@ Bitmap::render_text (const lay::RenderText &text)
} else {

// Create a sub-renderer so we do not need to clear *this
lay::BitmapRenderer hr (m_width, m_height, m_resolution);
lay::BitmapRenderer hr (m_width, m_height, m_resolution, m_font_resolution);

db::DHershey ht (text.text, text.font);
hr.reserve_edges (ht.count_edges ());
Expand Down
16 changes: 14 additions & 2 deletions src/laybasic/laybasic/layBitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ class LAYBASIC_PUBLIC Bitmap
* @param w The width of the bitmap
* @param h The height of the bitmap
* @param r The resolution of the bitmap
* @param rf The font resolution of the bitmap
*/
Bitmap (unsigned int w, unsigned int h, double r);
Bitmap (unsigned int w, unsigned int h, double r, double rf);

/**
* @brief Copy constructor
Expand Down Expand Up @@ -218,6 +219,11 @@ class LAYBASIC_PUBLIC Bitmap
*/
double resolution () const;

/**
* @brief Get the font resolution of the bitmap (applies to "Default" font)
*/
double font_resolution () const;

/**
* @brief Get the width of the bitmap
*/
Expand Down Expand Up @@ -311,7 +317,7 @@ class LAYBASIC_PUBLIC Bitmap
private:
unsigned int m_width;
unsigned int m_height;
double m_resolution;
double m_resolution, m_font_resolution;
std::vector<uint32_t *> m_scanlines;
std::vector<uint32_t *> m_free;
uint32_t *m_empty_scanline;
Expand Down Expand Up @@ -357,6 +363,12 @@ Bitmap::resolution () const
return m_resolution;
}

inline double
Bitmap::font_resolution () const
{
return m_font_resolution;
}

inline unsigned int
Bitmap::width () const
{
Expand Down
12 changes: 6 additions & 6 deletions src/laybasic/laybasic/layBitmapRenderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace lay
// ----------------------------------------------------------------------------------------------
// BitmapRenderer implementation

BitmapRenderer::BitmapRenderer (unsigned int width, unsigned int height, double resolution)
: Renderer (width, height, resolution),
BitmapRenderer::BitmapRenderer (unsigned int width, unsigned int height, double resolution, double font_resolution)
: Renderer (width, height, resolution, font_resolution),
m_xmin (0.0), m_xmax (0.0), m_ymin (0.0), m_ymax (0.0),
m_ortho (true)
{
Expand Down Expand Up @@ -386,12 +386,12 @@ BitmapRenderer::draw (const db::Shape &shape, const db::CplxTrans &trans,
if (m_draw_texts && text) {

db::DFTrans fp (db::DFTrans::r0);
db::DCoord h = trans.ctrans (m_default_text_size);
db::DCoord h = trans.mag () * m_default_text_size;
db::Font font = shape.text_font () == db::NoFont ? m_font : shape.text_font ();

if (m_apply_text_trans && font != db::NoFont && font != db::DefaultFont) {
fp = db::DFTrans (trans.fp_trans () * shape.text_trans ());
h = trans.ctrans (shape.text_size () > 0 ? shape.text_size () : m_default_text_size);
h = trans.mag () * (shape.text_size () > 0 ? shape.text_size () : m_default_text_size);
}

db::HAlign halign = shape.text_halign ();
Expand Down Expand Up @@ -1087,12 +1087,12 @@ BitmapRenderer::draw (const db::Text &txt, const db::CplxTrans &trans,
if (m_draw_texts && text) {

db::DFTrans fp (db::DFTrans::r0);
db::DCoord h = trans.ctrans (m_default_text_size);
db::DCoord h = trans.mag () * m_default_text_size;
db::Font font = txt.font () == db::NoFont ? m_font : txt.font ();

if (m_apply_text_trans && font != db::NoFont && font != db::DefaultFont) {
fp = db::DFTrans (trans.fp_trans () * txt.trans ());
h = trans.ctrans (txt.size () > 0 ? txt.size () : m_default_text_size);
h = trans.mag () * (txt.size () > 0 ? txt.size () : m_default_text_size);
}

double fy = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion src/laybasic/laybasic/layBitmapRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LAYBASIC_PUBLIC BitmapRenderer
/**
* @brief The default ctor
*/
BitmapRenderer (unsigned int width, unsigned int height, double resolution);
BitmapRenderer (unsigned int width, unsigned int height, double resolution, double font_resolution);

/**
* @brief Reserve space for n edges
Expand Down
4 changes: 2 additions & 2 deletions src/laybasic/laybasic/layBitmapsToImage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ static void create_precursor_bitmaps (const std::vector<lay::ViewOp> &view_ops_i
mutex->lock ();
}

lay::Bitmap &bp = precursors.insert (std::make_pair (bm_index, lay::Bitmap (width, height, 1.0))).first->second;
lay::Bitmap &bp = precursors.insert (std::make_pair (bm_index, lay::Bitmap (width, height, 1.0, 1.0))).first->second;
const LineStyleInfo &ls_info = ls.style (op.line_style_index ()).scaled (op.width ());

for (unsigned int y = 0; y < height; y++) {
Expand Down Expand Up @@ -961,7 +961,7 @@ bitmap_to_bitmap (const lay::ViewOp &view_op, const lay::Bitmap &bitmap,
lay::Bitmap precursor;
if (ls_info.width () > 0) {

precursor = lay::Bitmap (width, height, 1.0);
precursor = lay::Bitmap (width, height, 1.0, 1.0);

LineStyleInfo lsi = ls_info;

Expand Down
52 changes: 35 additions & 17 deletions src/laybasic/laybasic/layLayoutCanvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ LayoutCanvas::LayoutCanvas (lay::LayoutViewBase *view)
m_background (0), m_foreground (0), m_active (0),
m_oversampling (1),
m_hrm (false),
m_srm (false),
m_need_redraw (false),
m_redraw_clearing (false),
m_redraw_force_update (true),
Expand Down Expand Up @@ -201,11 +202,15 @@ LayoutCanvas::~LayoutCanvas ()
double
LayoutCanvas::resolution () const
{
if (m_hrm) {
return 1.0 / m_oversampling;
} else {
return 1.0 / (m_oversampling * dpr ());
}
return (m_srm ? 1.0 : 1.0 / m_oversampling) * (m_hrm ? 1.0 : 1.0 / dpr ());
}

double
LayoutCanvas::font_resolution () const
{
// NOTE: for font resolution we do not include the subresolution mode - otherwise
// the labels will become very hard to read.
return (1.0 / m_oversampling) * (m_hrm ? 1.0 : 1.0 / dpr ());
}

#if defined(HAVE_QT)
Expand Down Expand Up @@ -283,6 +288,16 @@ LayoutCanvas::set_highres_mode (bool hrm)
}
}

void
LayoutCanvas::set_subres_mode (bool srm)
{
if (srm != m_srm) {
m_image_cache.clear ();
m_srm = srm;
do_redraw_all ();
}
}

double
LayoutCanvas::dpr () const
{
Expand Down Expand Up @@ -363,7 +378,7 @@ LayoutCanvas::prepare_drawing ()
{
if (m_need_redraw) {

BitmapViewObjectCanvas::set_size (m_viewport_l.width (), m_viewport_l.height (), resolution ());
BitmapViewObjectCanvas::set_size (m_viewport_l.width (), m_viewport_l.height (), resolution (), font_resolution ());

if (! mp_image ||
(unsigned int) mp_image->width () != m_viewport_l.width () ||
Expand Down Expand Up @@ -399,7 +414,7 @@ LayoutCanvas::prepare_drawing ()
++c;
}

mp_redraw_thread->commit (m_layers, m_viewport_l, resolution ());
mp_redraw_thread->commit (m_layers, m_viewport_l, resolution (), font_resolution ());

if (tl::verbosity () >= 20) {
tl::info << "Restored image from cache";
Expand Down Expand Up @@ -449,7 +464,7 @@ LayoutCanvas::prepare_drawing ()
}

if (m_redraw_clearing) {
mp_redraw_thread->start (mp_view->synchronous () ? 0 : mp_view->drawing_workers (), m_layers, m_viewport_l, resolution (), m_redraw_force_update);
mp_redraw_thread->start (mp_view->synchronous () ? 0 : mp_view->drawing_workers (), m_layers, m_viewport_l, resolution (), font_resolution (), m_redraw_force_update);
} else {
mp_redraw_thread->restart (m_need_redraw_layer);
}
Expand Down Expand Up @@ -635,8 +650,8 @@ class DetachedViewObjectCanvas
: public BitmapViewObjectCanvas
{
public:
DetachedViewObjectCanvas (tl::Color bg, tl::Color fg, tl::Color ac, unsigned int width_l, unsigned int height_l, double resolution, tl::PixelBuffer *img)
: BitmapViewObjectCanvas (width_l, height_l, resolution),
DetachedViewObjectCanvas (tl::Color bg, tl::Color fg, tl::Color ac, unsigned int width_l, unsigned int height_l, double resolution, double font_resolution, tl::PixelBuffer *img)
: BitmapViewObjectCanvas (width_l, height_l, resolution, font_resolution),
m_bg (bg), m_fg (fg), m_ac (ac), mp_image (img)
{
// TODO: Good choice?
Expand Down Expand Up @@ -721,7 +736,7 @@ class DetachedViewObjectCanvasMono
{
public:
DetachedViewObjectCanvasMono (bool bg, bool fg, bool ac, unsigned int width, unsigned int height)
: BitmapViewObjectCanvas (width, height, 1.0),
: BitmapViewObjectCanvas (width, height, 1.0, 1.0),
m_bg (bg), m_fg (fg), m_ac (ac)
{
// .. nothing yet ..
Expand Down Expand Up @@ -754,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 @@ -791,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, &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 @@ -804,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, 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 Expand Up @@ -852,7 +870,7 @@ LayoutCanvas::image_with_options_mono (unsigned int width, unsigned int height,
lay::RedrawThread redraw_thread (&rd_canvas, mp_view);

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

tl::BitmapBuffer img (width, height);
Expand All @@ -872,7 +890,7 @@ LayoutCanvas::screenshot ()
tl::PixelBuffer img (m_viewport.width (), m_viewport.height ());
img.fill (m_background);

DetachedViewObjectCanvas vo_canvas (background_color (), foreground_color (), active_color (), m_viewport_l.width (), m_viewport_l.height (), resolution (), &img);
DetachedViewObjectCanvas vo_canvas (background_color (), foreground_color (), active_color (), m_viewport_l.width (), m_viewport_l.height (), resolution (), font_resolution (), &img);

// and paint the background objects. It uses "img" to paint on.
do_render_bg (m_viewport_l, vo_canvas);
Expand Down
Loading

0 comments on commit ea6ffb9

Please sign in to comment.