@@ -15991,6 +15991,7 @@ DVI}
15991
15991
@!pdf_draftmode_value: integer;
15992
15992
@!pdf_cur_Tm_a: integer; {|a| value of the current text matrix, i.e., the current
15993
15993
horizontal scaling factor}
15994
+ @!pdf_last_f: internal_font_number; {last font in PDF output page; this can differ from |pdf_f|}
15994
15995
@!pdf_last_fs: internal_font_number; {last font size in PDF output page}
15995
15996
@!pdf_dummy_font: internal_font_number; {font used to insert artificial interword spaces}
15996
15997
@@ -16042,17 +16043,21 @@ begin
16042
16043
end;
16043
16044
end;
16044
16045
16045
- procedure pdf_set_textmatrix(v, v_out: scaled; f: internal_font_number);
16046
- {set the next starting point to |cur_h|, |cur_v|}
16046
+ function get_font_auto_expand_ratio(f: internal_font_number): integer;
16047
+ {return |pdf_font_expand_ratio[f]| if f is auto-expanded, 0 otherwise}
16048
+ begin
16049
+ if pdf_font_auto_expand[f] then
16050
+ get_font_auto_expand_ratio := pdf_font_expand_ratio[f]
16051
+ else
16052
+ get_font_auto_expand_ratio := 0;
16053
+ end;
16054
+
16055
+ procedure pdf_set_text_pos(v, v_out: scaled; f: internal_font_number);
16056
+ {set the next starting point for text to |cur_h|, |cur_v|}
16047
16057
var pdf_new_Tm_a: integer; {|a| value of the new text matrix}
16048
16058
begin
16049
16059
pdf_out(" ");
16050
- if f = pdf_f then
16051
- pdf_new_Tm_a := pdf_cur_Tm_a
16052
- else if not pdf_font_auto_expand[f] then
16053
- pdf_new_Tm_a := 0
16054
- else
16055
- pdf_new_Tm_a := pdf_font_expand_ratio[f];
16060
+ pdf_new_Tm_a := get_font_auto_expand_ratio(f);
16056
16061
if (pdf_new_Tm_a <> 0) or
16057
16062
((pdf_new_Tm_a = 0) and (pdf_cur_Tm_a <> 0)) then begin
16058
16063
pdf_print_real(1000 + pdf_new_Tm_a, 3);
@@ -16161,6 +16166,7 @@ label found, found1;
16161
16166
var p: pointer;
16162
16167
k: internal_font_number;
16163
16168
begin
16169
+ pdf_f := f;
16164
16170
if not font_used[f] then
16165
16171
pdf_init_font(f);
16166
16172
set_ff(f); {set |ff| to the tfm number of the font sharing the font object
@@ -16176,15 +16182,15 @@ begin
16176
16182
end;
16177
16183
pdf_append_list(f)(pdf_font_list); {|f| not found in |pdf_font_list|, append it now}
16178
16184
found:
16179
- if (k = pdf_f ) and (font_size[f] = pdf_last_fs) then
16185
+ if (k = pdf_last_f ) and (font_size[f] = pdf_last_fs) then
16180
16186
return;
16181
16187
pdf_print("/F");
16182
16188
pdf_print_int(k);
16183
16189
pdf_print_resname_prefix;
16184
16190
pdf_out(" ");
16185
16191
pdf_print_real(divide_scaled(font_size[f], one_hundred_bp, 6), 4);
16186
16192
pdf_print(" Tf");
16187
- pdf_f := k;
16193
+ pdf_last_f := k;
16188
16194
pdf_last_fs := font_size[f];
16189
16195
end;
16190
16196
@@ -16194,6 +16200,7 @@ begin
16194
16200
pdf_print_ln("BT");
16195
16201
pdf_doing_text := true;
16196
16202
pdf_f := null_font;
16203
+ pdf_last_f := null_font;
16197
16204
pdf_last_fs := 0;
16198
16205
pdf_doing_string := false;
16199
16206
pdf_cur_Tm_a := 0;
@@ -16222,13 +16229,18 @@ var s_out, v, v_out: scaled;
16222
16229
s: integer;
16223
16230
must_end_string: boolean; {must we end the current string?}
16224
16231
must_insert_space: boolean; {must we insert an interword space?}
16225
- move_by_tm : boolean; {movement must be set using Tm operator}
16226
-
16232
+ must_set_text_pos : boolean; {move must be set using Tm or Td operator}
16233
+ move_looks_like_interword_space: boolean; {move could be a space}
16227
16234
begin
16235
+ must_insert_space := false;
16236
+ must_end_string := false;
16237
+
16228
16238
if not pdf_doing_text then
16229
16239
pdf_begin_text;
16230
- if (not gen_faked_interword_space and pdf_f <> f)
16231
- or (gen_faked_interword_space and not (font_used[f] and font_used[pdf_f]))
16240
+
16241
+ {delay font switch if we must insert interword space}
16242
+ if (not gen_faked_interword_space and pdf_f <> f)
16243
+ or (gen_faked_interword_space and not (font_used[f] and font_used[pdf_f]))
16232
16244
then begin
16233
16245
pdf_end_string;
16234
16246
pdf_set_font(f);
@@ -16261,17 +16273,21 @@ begin
16261
16273
v_out := 0;
16262
16274
end;
16263
16275
16264
- must_insert_space := false;
16265
- must_end_string := false;
16266
- move_by_tm := (v <> 0) or (abs(s) >= @'100000);
16267
-
16268
- if move_by_tm then begin
16276
+ must_set_text_pos := (v <> 0)
16277
+ or (abs(s) >= @'100000)
16278
+ or (get_font_auto_expand_ratio(f) <> pdf_cur_Tm_a)
16279
+ or get_font_auto_expand_ratio(f) <> get_font_auto_expand_ratio(pdf_f);
16280
+ if must_set_text_pos then begin
16269
16281
must_end_string := true;
16270
16282
end;
16271
16283
16284
+ move_looks_like_interword_space := (space(f) > one_bp)
16285
+ and (s_out > space(f) - space_shrink(f) - one_bp div 10)
16286
+ and (v = 0);
16287
+
16272
16288
if gen_faked_interword_space
16273
- and (not move_by_tm)
16274
- and (s_out > space(f) - space_shrink(f) - 65536 )
16289
+ and move_looks_like_interword_space
16290
+ and (not must_set_text_pos )
16275
16291
then begin
16276
16292
must_insert_space := true;
16277
16293
end;
@@ -16294,13 +16310,19 @@ begin
16294
16310
pdf_end_string;
16295
16311
{insert a space char from the dummy font if needed}
16296
16312
if (must_insert_space) and (not pdf_font_has_space_char[f]) then begin
16297
- pdf_insert_interword_space; {this will change |pdf_f|}
16298
- pdf_set_font(f);
16313
+ pdf_insert_interword_space; {this will change the current font}
16299
16314
end;
16300
- pdf_set_textmatrix(v, v_out, f);
16315
+ pdf_set_font(f);
16316
+ pdf_set_text_pos(v, v_out, f);
16301
16317
s := 0;
16302
16318
end;
16303
16319
16320
+ {do font switch here after interword space could have been inserted}
16321
+ if gen_faked_interword_space and (pdf_f <> f) then begin
16322
+ pdf_end_string;
16323
+ pdf_set_font(f);
16324
+ end;
16325
+
16304
16326
if not pdf_doing_string then begin
16305
16327
pdf_print(" [");
16306
16328
if s = 0 then
@@ -27663,7 +27685,7 @@ else begin q:=glue_ptr(p);
27663
27685
("shrinkable glue, e.g., `\vss' or `\vskip 0pt minus 1fil'.")@/
27664
27686
("Such glue doesn't belong there; but you can safely proceed,")@/
27665
27687
("since the offensive shrinkability has been made finite.");
27666
- error;
27688
+ error;
27667
27689
end;
27668
27690
r:=new_spec(q); shrink_order(r):=normal; delete_glue_ref(q);
27669
27691
glue_ptr(p):=r; q:=r;
0 commit comments