From 36ae937be87346dac84187fca645b6f4c6bb62e4 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 15 Nov 2023 00:22:54 +0100 Subject: [PATCH] Revert "Set space width in fz_font for use with stext-device." This reverts commit b9d3868c390017eadeb36a864771a2cb673504ca. --- include/mupdf/fitz/font.h | 2 -- source/fitz/font.c | 2 -- source/fitz/stext-device.c | 17 ++++++++--------- source/pdf/pdf-font.c | 6 ------ 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h index 241a6f8877..f4af553338 100644 --- a/include/mupdf/fitz/font.h +++ b/include/mupdf/fitz/font.h @@ -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; diff --git a/source/fitz/font.c b/source/fitz/font.c index 95da0f1f1c..23320e2d22 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -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; diff --git a/source/fitz/stext-device.c b/source/fitz/stext-device.c index b4f5a6d0ca..3545a15ab6 100644 --- a/source/fitz/stext-device.c +++ b/source/fitz/stext-device.c @@ -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 @@ -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; @@ -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; } @@ -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)) @@ -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)) diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index 376cfea02a..fe61f7d15c 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -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) { @@ -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; }