Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85b42b5

Browse files
committed
Generate rasterized hatching at correct DPI.
The hatch buffer was created at 72 pixels, with the assumption that that is the "unit square" (1in*1in). However, with default DPI increased to 100, that buffer is actually too small, causing hatching to be denser than it should be. On test images where the DPI was set really low, the hatching was less dense than it should be. Fixes #4108.
1 parent 41f4e37 commit 85b42b5

File tree

12 files changed

+12
-4
lines changed

12 files changed

+12
-4
lines changed

doc/users/dflt_style_changes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,11 @@ The behavior of the PS and Agg backends was DPI dependent, thus::
625625

626626
There is no API level control of the hatch color or linewidth.
627627

628+
Hatching patterns are now rendered at a consistent density, regardless of DPI.
629+
Formerly, high DPI figures would be more dense than the default, and low DPI
630+
figures would be less dense. This old behavior cannot be directly restored,
631+
but the density may be increased by repeating the hatch specifier.
632+
628633

629634
.. _default_changes_font:
630635

src/_backend_agg.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
5858
rendererBase.clear(_fill_color);
5959
rendererAA.attach(rendererBase);
6060
rendererBin.attach(rendererBase);
61-
hatchRenderingBuffer.attach(hatchBuffer, HATCH_SIZE, HATCH_SIZE, HATCH_SIZE * 4);
61+
hatch_size = int(dpi);
62+
hatchBuffer = new agg::int8u[hatch_size * hatch_size * 4];
63+
hatchRenderingBuffer.attach(hatchBuffer, hatch_size, hatch_size, hatch_size * 4);
6264
}
6365

6466
RendererAgg::~RendererAgg()
6567
{
68+
delete[] hatchBuffer;
6669
delete[] alphaBuffer;
6770
delete[] pixBuffer;
6871
}

src/_backend_agg.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ class RendererAgg
239239
void *lastclippath;
240240
agg::trans_affine lastclippath_transform;
241241

242-
static const size_t HATCH_SIZE = 72;
243-
agg::int8u hatchBuffer[HATCH_SIZE * HATCH_SIZE * 4];
242+
size_t hatch_size;
243+
agg::int8u *hatchBuffer;
244244
agg::rendering_buffer hatchRenderingBuffer;
245245

246246
agg::rgba _fill_color;
@@ -359,7 +359,7 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
359359
agg::trans_affine hatch_trans;
360360
hatch_trans *= agg::trans_affine_scaling(1.0, -1.0);
361361
hatch_trans *= agg::trans_affine_translation(0.0, 1.0);
362-
hatch_trans *= agg::trans_affine_scaling(HATCH_SIZE, HATCH_SIZE);
362+
hatch_trans *= agg::trans_affine_scaling(hatch_size, hatch_size);
363363
hatch_path_trans_t hatch_path_trans(hatch_path, hatch_trans);
364364
hatch_path_curve_t hatch_path_curve(hatch_path_trans);
365365
hatch_path_stroke_t hatch_path_stroke(hatch_path_curve);

0 commit comments

Comments
 (0)