Skip to content

Commit 8c2e9e7

Browse files
committed
Issue 4902: Fix linewidth of stroked text.
This relies on an upstream fix from MuPDF that will be in the 1.28.0 release, but is not in 1.27.2.
1 parent 409eede commit 8c2e9e7

1 file changed

Lines changed: 19 additions & 27 deletions

File tree

src/extra.i

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,6 @@ struct jm_lineart_device
16371637
fz_rect pathrect = {};
16381638
int clips = {};
16391639
int linecount = {};
1640-
float linewidth = {};
16411640
int path_type = {};
16421641
long depth = {};
16431642
size_t seqno = {};
@@ -1747,7 +1746,8 @@ static void jm_trace_text_span(
17471746
fz_colorspace* colorspace,
17481747
const float* color,
17491748
float alpha,
1750-
size_t seqno
1749+
size_t seqno,
1750+
const fz_stroke_state* stroke
17511751
)
17521752
{
17531753
//printf("extra.jm_trace_text_span(): seqno=%zi\n", seqno);
@@ -1900,24 +1900,20 @@ static void jm_trace_text_span(
19001900
{
19011901
rgb[0] = rgb[1] = rgb[2] = 0;
19021902
}
1903-
double linewidth;
1904-
if (dev->linewidth > 0) // width of character border
1903+
if (0)
19051904
{
1906-
linewidth = (double) dev->linewidth;
1907-
}
1908-
else
1909-
{
1910-
linewidth = fsize * 0.05; // default: 5% of font size
1905+
std::cout << " fsize=" << fsize;
1906+
if (stroke)
1907+
{
1908+
std::cout << " linewidth=" << stroke->linewidth;
1909+
}
1910+
std::cout << "\n";
19111911
}
1912-
if (0) std::cout
1913-
<< " dev->linewidth=" << dev->linewidth
1914-
<< " fsize=" << fsize
1915-
<< " linewidth=" << linewidth
1916-
<< "\n";
19171912
dict_setitem_drop(span_dict, dictkey_color, Py_BuildValue("fff", rgb[0], rgb[1], rgb[2]));
19181913
dict_setitem_drop(span_dict, dictkey_size, PyFloat_FromDouble(fsize));
19191914
dict_setitemstr_drop(span_dict, "opacity", PyFloat_FromDouble((double) alpha));
1920-
dict_setitemstr_drop(span_dict, "linewidth", PyFloat_FromDouble((double) linewidth));
1915+
if (stroke)
1916+
dict_setitemstr_drop(span_dict, "linewidth", PyFloat_FromDouble((double) stroke->linewidth));
19211917
dict_setitemstr_drop(span_dict, "spacewidth", PyFloat_FromDouble(space_adv));
19221918
dict_setitem_drop(span_dict, dictkey_type, PyLong_FromLong((long) type));
19231919
dict_setitem_drop(span_dict, dictkey_bbox, JM_py_from_rect(span_bbox));
@@ -1987,7 +1983,7 @@ static void jm_fill_image_mask(
19871983
jm_increase_seqno(ctx, dev);
19881984
}
19891985

1990-
static void jm_dev_linewidth(
1986+
static void jm_stroke_path(
19911987
fz_context* ctx,
19921988
fz_device* dev_,
19931989
const fz_path* path,
@@ -1999,11 +1995,6 @@ static void jm_dev_linewidth(
19991995
fz_color_params color_params
20001996
)
20011997
{
2002-
jm_tracedraw_device* dev = (jm_tracedraw_device*) dev_;
2003-
if (0) std::cout << "jm_dev_linewidth(): changing dev->linewidth from " << dev->linewidth
2004-
<< " to stroke->linewidth=" << stroke->linewidth
2005-
<< "\n";
2006-
dev->linewidth = stroke->linewidth;
20071998
jm_increase_seqno(ctx, dev_);
20081999
}
20092000

@@ -2015,13 +2006,14 @@ static void jm_trace_text(
20152006
fz_colorspace* colorspace,
20162007
const float* color,
20172008
float alpha,
2018-
size_t seqno
2009+
size_t seqno,
2010+
const fz_stroke_state* stroke
20192011
)
20202012
{
20212013
fz_text_span* span;
20222014
for (span = text->head; span; span = span->next)
20232015
{
2024-
jm_trace_text_span(dev, span, type, ctm, colorspace, color, alpha, seqno);
2016+
jm_trace_text_span(dev, span, type, ctm, colorspace, color, alpha, seqno, stroke);
20252017
}
20262018
}
20272019

@@ -2044,7 +2036,7 @@ jm_tracedraw_fill_text(
20442036
)
20452037
{
20462038
jm_tracedraw_device* dev = (jm_tracedraw_device*) dev_;
2047-
jm_trace_text(dev, text, 0, ctm, colorspace, color, alpha, dev->seqno);
2039+
jm_trace_text(dev, text, 0, ctm, colorspace, color, alpha, dev->seqno, NULL);
20482040
dev->seqno += 1;
20492041
}
20502042

@@ -2062,7 +2054,7 @@ jm_tracedraw_stroke_text(
20622054
)
20632055
{
20642056
jm_tracedraw_device* dev = (jm_tracedraw_device*) dev_;
2065-
jm_trace_text(dev, text, 1, ctm, colorspace, color, alpha, dev->seqno);
2057+
jm_trace_text(dev, text, 1, ctm, colorspace, color, alpha, dev->seqno, stroke);
20662058
dev->seqno += 1;
20672059
}
20682060

@@ -2076,7 +2068,7 @@ jm_tracedraw_ignore_text(
20762068
)
20772069
{
20782070
jm_tracedraw_device* dev = (jm_tracedraw_device*) dev_;
2079-
jm_trace_text(dev, text, 3, ctm, nullptr, nullptr, 1, dev->seqno);
2071+
jm_trace_text(dev, text, 3, ctm, nullptr, nullptr, 1, dev->seqno, NULL);
20802072
dev->seqno += 1;
20812073
}
20822074

@@ -2105,7 +2097,7 @@ mupdf::FzDevice JM_new_texttrace_device(PyObject* out)
21052097
dev->super.close_device = nullptr;
21062098
dev->super.drop_device = jm_lineart_drop_device;
21072099
dev->super.fill_path = jm_fill_path;
2108-
dev->super.stroke_path = jm_dev_linewidth;
2100+
dev->super.stroke_path = jm_stroke_path;
21092101
dev->super.clip_path = nullptr;
21102102
dev->super.clip_stroke_path = nullptr;
21112103

0 commit comments

Comments
 (0)