Skip to content

Commit

Permalink
Revert "Set space width in fz_font for use with stext-device."
Browse files Browse the repository at this point in the history
This reverts commit b9d3868.
  • Loading branch information
ccxvii committed Nov 14, 2023
1 parent 0f3ed35 commit 36ae937
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
2 changes: 0 additions & 2 deletions include/mupdf/fitz/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,6 @@ struct fz_font
short width_default; /* in 1000 units */
short *width_table; /* in 1000 units */

float space_width; /* for space detection -- used by PDF only */

/* cached glyph metrics */
float **advance_cache;

Expand Down
2 changes: 0 additions & 2 deletions source/fitz/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ fz_new_font(fz_context *ctx, const char *name, int use_glyph_bbox, int glyph_cou
font->bbox.x1 = 1;
font->bbox.y1 = 1;

font->space_width = 0.25;

font->glyph_count = glyph_count;

font->bbox_table = NULL;
Expand Down
17 changes: 8 additions & 9 deletions source/fitz/stext-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ void fz_add_layout_char(fz_context *ctx, fz_layout_block *block, float x, float
/* Extract text into blocks and lines. */

#define PARAGRAPH_DIST 1.5f
#define SPACE_DIST 0.15f
#define SPACE_MAX_DIST 0.8f
#define BASE_MAX_DIST 0.8f

typedef struct
Expand Down Expand Up @@ -343,9 +345,6 @@ fz_add_stext_char_imp(fz_context *ctx, fz_stext_device *dev, fz_font *font, int
float spacing = 0;
float base_offset = 0;

float space_dist = font->space_width * 0.5f;
float space_max_dist = font->space_width * 3.0f;

/* Preserve RTL-ness only (and ignore level) so we can use bit 2 as "visual" tag for reordering pass. */
bidi = bidi & 1;

Expand Down Expand Up @@ -458,7 +457,7 @@ fz_add_stext_char_imp(fz_context *ctx, fz_stext_device *dev, fz_font *font, int
* are probably seeing characters emitted in
* logical order.
*/
if (fabsf(logical_spacing) < space_dist)
if (fabsf(logical_spacing) < SPACE_DIST)
{
new_line = 0;
}
Expand All @@ -467,21 +466,21 @@ fz_add_stext_char_imp(fz_context *ctx, fz_stext_device *dev, fz_font *font, int
* in an LTR context, we're seeing them emitted in visual order
* and should flag them for reordering!
*/
else if (fabsf(spacing) < space_dist)
else if (fabsf(spacing) < SPACE_DIST)
{
bidi = 3; /* mark line as visual */
new_line = 0;
}

/* And any other small jump could be a missing space. */
else if (logical_spacing < 0 && logical_spacing > -space_max_dist)
else if (logical_spacing < 0 && logical_spacing > -SPACE_MAX_DIST)
{
if (wmode == 0 && may_add_space(dev->lastchar))
add_space = 1;
new_line = 0;
}

else if (spacing > 0 && spacing < space_max_dist)
else if (spacing > 0 && spacing < SPACE_MAX_DIST)
{
bidi = 3; /* mark line as visual */
if (wmode == 0 && may_add_space(dev->lastchar))
Expand All @@ -499,12 +498,12 @@ fz_add_stext_char_imp(fz_context *ctx, fz_stext_device *dev, fz_font *font, int
/* LTR or neutral character */
else
{
if (fabsf(spacing) < space_dist)
if (fabsf(spacing) < SPACE_DIST)
{
/* Motion is in line and small enough to ignore. */
new_line = 0;
}
else if (spacing > 0 && spacing < space_max_dist)
else if (spacing > 0 && spacing < SPACE_MAX_DIST)
{
/* Motion is forward in line and large enough to warrant us adding a space. */
if (wmode == 0 && may_add_space(dev->lastchar))
Expand Down
6 changes: 0 additions & 6 deletions source/pdf/pdf-font.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,6 @@ pdf_load_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *dict)
pdf_obj *charprocs;
pdf_font_desc *fontdesc = NULL;
int type3 = 0;
int space_width;

if ((fontdesc = pdf_find_item(ctx, pdf_drop_font_imp, dict)) != NULL)
{
Expand Down Expand Up @@ -1600,11 +1599,6 @@ pdf_load_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *dict)
fz_rethrow(ctx);
}

/* Set the space width for stext-device's missing space detection */
space_width = pdf_lookup_hmtx(ctx, fontdesc, 32).w;
if (space_width > 0 && space_width < 1000)
fontdesc->font->space_width = space_width * 0.001f;

return fontdesc;
}

Expand Down

0 comments on commit 36ae937

Please sign in to comment.