mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-18 00:26:04 +00:00
M2: without codespace ranges, a bfchar CID mapping matches only codes of its own source length (view.render-cid-fonts)
hayro-cmap patch 4: text CMaps record each bf entry's source length (BfRange::code_len). Where no codespace range gives a code its length, the bfchar fallback of lookup_cid_code takes the entry's own length, so the first byte of <fe96> is no longer taken for <00fe>. CMaps with codespace ranges are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pq7HyCHD1R3rywQBPCHXZA
This commit is contained in:
1 parent
37e5708ed2
commit
3a3fe00f69
4 files changed
+57
-10
No files matched your search
Vendored
+1
-1
@@ -47,7 +47,7 @@ Other resource categories retain their existing parent-chain lookup.
|
||||
| winit | 0.30.13 | Apache-2.0 | (1) on Windows 11 (build 22000 and later), `WM_DPICHANGED` applies the rect Windows suggests. It used to nudge the window onto the monitor `MonitorFromWindow` names, which during a drag is still the monitor being left; the nudge sent another `WM_DPICHANGED`, so a window dragged to a monitor with another scale factor grew and stayed on the wrong monitor at the wrong scale (#324). Backport of winit master 488c036a ([winit#4341](https://github.com/rust-windowing/winit/pull/4341)), which no 0.30 release has; Windows 10 keeps the old adjustment, as on winit master. (2) on Wayland, a seat's text input is destroyed when the seat goes away, not whenever it loses a capability: losing any capability (a touch screen or tablet unplugged, a remote-desktop session ending) destroyed it, and only an added capability recreated it, so IME stopped working until restart. Port of [winit#4747](https://github.com/rust-windowing/winit/pull/4747); (3) on Windows, an IME composition reports its cursor from `GCS_CURSORPOS` only when `WM_IME_COMPOSITION` says it is set, and at the end of the composition otherwise: the Microsoft Korean IME never sets it, so the cursor read as 0 (egui then drew no caret while composing; it now draws it after the syllable). Port of [winit#4746](https://github.com/rust-windowing/winit/pull/4746); (4) on Windows, a hidden window is not maximized until it is shown, and a hidden window shown while maximized gets one `ShowWindow(SW_MAXIMIZE)`: `SW_MAXIMIZE` shows a hidden window, so PdfCraft, which eframe keeps hidden until its first frame is drawn, appeared unpainted (white) when it restored a maximized window, and could lose its focus. Port of [winit#4587](https://github.com/rust-windowing/winit/pull/4587) (the later, focus-safe form of [winit#4575](https://github.com/rust-windowing/winit/pull/4575)); (5) on X11, when allowing or disallowing IME replaces the focused window's input context (egui does it each time a text field gains or loses focus), the new context is focused: no focus event follows, so it stayed unfocused until the window lost and regained focus. Port of [winit#4727](https://github.com/rust-windowing/winit/pull/4727); (6) on macOS, `insertText` commits through IME when a composition was started (`pending_commit`, set by `setMarkedText`) rather than when marked text is left: input methods that end a composition with `unmarkText` before `insertText` lost the text, and Apple Korean dropped the key typed after a syllable (`한` then `5` or `;`); other `insertText` calls stay `KeyboardInput`; a commit outside a key press (a candidate clicked with the mouse, dictation) clears the marked text and leaves no key to swallow, as in [winit#4748](https://github.com/rust-windowing/winit/pull/4748) (without it the next key, such as Backspace, was lost). `validAttributesForMarkedText` lists the underline and marked-clause attributes, without which some input methods don't compose. Port of [winit#4650](https://github.com/rust-windowing/winit/pull/4650), the 0.30 backport of [winit#4651](https://github.com/rust-windowing/winit/pull/4651) (merged on winit master), with the underline attribute spelled as AppKit's `NSUnderlineStyleAttributeName` (`NSUnderline`); (7) on macOS, disallowing IME with a composition in progress (focus leaving a text field) tells the input method to discard its marked text (`discardMarkedText`): it kept composing it once IME was allowed again, so the abandoned syllable came back (`하`, then `가` typed in the next field, became `학`, then `하` + `가`; Japanese `か` then `さ` became `傘`). Port of [winit#4745](https://github.com/rust-windowing/winit/pull/4745); (8) on macOS, text inserted outside a key press without a composition (the emoji picker) is reported as `Ime::Commit`; it was dropped. Port of the emoji-picker part of [winit#4749](https://github.com/rust-windowing/winit/pull/4749) (0.30 backport of [winit#4748](https://github.com/rust-windowing/winit/pull/4748)); its `selectedRange` change for dictation is left out because it switches on press-and-hold for every held key (an accent menu instead of key repeat, and the chosen accent added after the repeated letters); (9) on macOS, a key whose text was committed through IME isn't also sent as `KeyboardInput` unless AppKit forwards it as a command (Enter): Apple Korean answers Space with no syllable in progress with `setMarkedText(" ")`, `insertText(" ")`, `setMarkedText("")`, and the last call reset winit's state, so the space arrived twice. Same goal as [winit#4478](https://github.com/rust-windowing/winit/pull/4478), whose changes don't reach this call order (macOS 14); to be proposed upstream there; (10) on macOS, when the first key in a fresh app reaches Apple Korean's `insertText` as a raw compatibility jamo instead of starting a composition, that key is interpreted once more, synchronously, before it is sent as `KeyboardInput` (g k s typed ㅎㅏㄴ instead of 한); only an unmodified, Line truncated
|
||||
| egui-wgpu | 0.36.2 | MIT OR Apache-2.0 | (1) `winit::surface_fit`: a window's surface is configured within the device's `max_texture_dimension_2d`, both sides shrunk by one factor that egui then draws at (`pixels_per_point × render_scale`), so the whole window is drawn into the surface (on DX12 it is stretched over the window and lines up with the pointer; wgpu's GL backend copies it unscaled into a corner); the longer side becomes exactly the limit; the depth and MSAA textures follow, and a recreated surface starts again from the window's own size. egui-wgpu configured the window's size as is, and `Surface::configure` panics beyond the limit: a window restored at another monitor's scale (opening an Outlook attachment on a mixed-DPI laptop asked an 8192-pixel device for 8600 × 3423, #577) or stretched across monitors closed PdfCraft, before its window appeared when it happened at start-up ([emilk/egui#8361](https://github.com/emilk/egui/issues/8361)). The published crate leaves out egui's licence files; `LICENSE-APACHE` and `LICENSE-MIT` are from the 0.36.2 tag; (2) `winit::catch_errors`: a new window's surface is configured inside wgpu error scopes (validation, out of memory, internal), and a failure is returned as `WgpuError::ConfigureSurface` (for the root window at start-up eframe returns it as `Error::Wgpu`, which PdfCraft retries with OpenGL); nothing is kept for the window. wgpu's default handler panicked instead, and eframe configures the root surface before the app is created, so a driver that can't configure one closed PdfCraft at launch (a 2015 Intel GPU through wgpu's GL backend timed out waiting for the GPU to go idle, `GpuWaitTimeout`, #519). Unchanged, so still a panic: an error in a later reconfigure (resize, a lost surface), a device lost during the first configure (wgpu reports it only to a callback), and a window shown at zero size (first configured on resize) | (1) `pdfcraft` `tests::a_window_larger_than_the_gpu_limit_gets_a_surface_within_it`, `tests::surface_fit_never_empties_or_overflows_a_surface`, and `tests::vendor_provenance_egui_wgpu_surface_fit_identity`, which keeps the patch in the build and in the paths that size a surface; (2) `pdfcraft` `tests::a_gpu_error_while_a_window_is_set_up_is_returned_not_a_panic` (a real device: an error inside `catch_errors` is returned, not a panic) and `tests::vendor_provenance_egui_wgpu_catch_errors_identity`, which keeps it around `add_surface`'s configure |
|
||||
| vello_common | 0.0.8 | Apache-2.0 OR MIT | (1) `clip::intersect` (the clip step every clipped path passes through) starts its row walk at the first row both paths have strips in, not the earlier of the two first rows. The walk visited every row from the top of the clip for each path (on the A1 sample's full-page canvas, about half its strip rows per stroke), and rows where one path has no strips produce no output, so the strips are unchanged (vello_common 0.1 starts at the later row too). Its cost grew with the page, and a full-page render of the A1 sample was about 30% faster; the output is byte-identical | (1) `clip::tests::intersect_walks_only_rows_both_paths_have_strips` counts the rows the walk visits (`cargo test --manifest-path vendor/vello_common/Cargo.toml`) and fails without the patch; the render crate's pixel tests run through the patched crate |
|
||||
| hayro-cmap | 0.1.0 | Apache-2.0 OR MIT | (1) malformed parts of a CMap (bad bfchar/bfrange entries, unresolvable `usecmap`, unparseable tail) are skipped instead of discarding the whole map, so search and redaction find text the edit layer can read (#3177); (2) a binary CMap's `usecmap` counts against the 16-level nesting limit as a text one does, where it passed its own depth and a self-referencing binary CMap recursed until the stack overflowed (from storytold/craft-libs#254); (4) `lookup_cid_code`'s `bfchar` fallback (used where a CMap writes its CID mappings as `bfchar`) applies only when the codespace ranges give the code the byte length being tried (ISO 32000-2 §9.7.6.2; `codespace_allows`, a CMap without codespace ranges defers to its `usecmap` base and then allows every code): bf entries don't record their code length, so the first byte of `<fe96>` matched the entry `<00fe>` and every two-byte code drew as two glyphs (PDFBOX-1282 `Characters_Arial.pdf` page 3). An unmapped code still advances one byte | (1) `hayro-cmap::tests::bad_bfchar_entry_is_skipped`, `unresolvable_usecmap_is_skipped`; (2) `tests::self_referencing_binary_usecmap_stops_at_the_nesting_limit`; (4) `hayro-cmap::tests::{bfchar_cid_fallback_takes_the_codespace_length, bfchar_cid_fallback_checks_each_byte_of_the_codespace}`, `raster::tests::a_bfchar_cmap_reads_codes_of_its_codespace_length` (pdfcraft-render) |
|
||||
| hayro-cmap | 0.1.0 | Apache-2.0 OR MIT | (1) malformed parts of a CMap (bad bfchar/bfrange entries, unresolvable `usecmap`, unparseable tail) are skipped instead of discarding the whole map, so search and redaction find text the edit layer can read (#3177); (2) a binary CMap's `usecmap` counts against the 16-level nesting limit as a text one does, where it passed its own depth and a self-referencing binary CMap recursed until the stack overflowed (from storytold/craft-libs#254); (4) `lookup_cid_code`'s `bfchar` fallback (used where a CMap writes its CID mappings as `bfchar`) applies only when the codespace ranges give the code the byte length being tried (ISO 32000-2 §9.7.6.2; `codespace_allows`, a CMap without codespace ranges defers to its `usecmap` base, and with none anywhere the entry's own source length decides, now recorded as `BfRange::code_len` for text CMaps): the first byte of `<fe96>` had matched the entry `<00fe>`, so the first byte of `<fe96>` matched the entry `<00fe>` and every two-byte code drew as two glyphs (PDFBOX-1282 `Characters_Arial.pdf` page 3). An unmapped code still advances one byte | (1) `hayro-cmap::tests::bad_bfchar_entry_is_skipped`, `unresolvable_usecmap_is_skipped`; (2) `tests::self_referencing_binary_usecmap_stops_at_the_nesting_limit`; (4) `hayro-cmap::tests::{bfchar_cid_fallback_takes_the_codespace_length, bfchar_cid_fallback_checks_each_byte_of_the_codespace, bfchar_cid_fallback_without_codespace_takes_the_source_length}`, `raster::tests::a_bfchar_cmap_reads_codes_of_its_codespace_length` (pdfcraft-render) |
|
||||
| hayro-postscript | 0.1.0 | Apache-2.0 OR MIT | (1) the token scanner's `object::read` skips `<<` and `>>` in a loop; it called itself once per delimiter, so a CMap stream holding a long run of `<` or `>` overflowed the stack and aborted the process (from storytold/craft-libs#263) | (1) `hayro-postscript::object::tests::long_open_dict_run_does_not_overflow`, `long_close_dict_run_does_not_overflow`, `dict_delimiters_are_skipped`, `nested_dict_delimiters_are_skipped` |
|
||||
|
||||
`hayro-postscript` is the crates.io 0.1.0 package plus patch (1). The local Cargo
|
||||
|
||||
Vendored
+2
@@ -410,6 +410,8 @@ fn parse_bf_segment(
|
||||
entries.push(BfRange {
|
||||
range: Range { start, end },
|
||||
dst_base,
|
||||
// PdfCraft patch (4): a binary CMap doesn't record the length.
|
||||
code_len: 0,
|
||||
});
|
||||
|
||||
prev_end = Some(end);
|
||||
|
||||
Vendored
+47
-9
@@ -455,9 +455,13 @@ impl CMap {
|
||||
// has, so the fallback only applies when the codespace ranges give
|
||||
// the code `byte_len` bytes (ISO 32000-2 §9.7.6.2). Otherwise the
|
||||
// first byte of `<fe96>` matched a `<00fe>` entry and a two-byte code
|
||||
// drew as two glyphs. A CMap with no codespace ranges keeps the old
|
||||
// fallback.
|
||||
if self.codespace_allows(code, byte_len, 0)
|
||||
// drew as two glyphs. A CMap with no codespace ranges anywhere uses
|
||||
// the length the entry's own source code was written with instead.
|
||||
let length_fits = match self.codespace_allows(code, byte_len, 0) {
|
||||
Some(allowed) => allowed,
|
||||
None => self.bf_code_has_length(code, byte_len),
|
||||
};
|
||||
if length_fits
|
||||
&& let Some(BfString::Char(lookup)) = self.lookup_bf_string_inner(code, false)
|
||||
{
|
||||
return Some(lookup as u32);
|
||||
@@ -469,21 +473,29 @@ impl CMap {
|
||||
.and_then(|b| b.lookup_cid_code(code, byte_len))
|
||||
}
|
||||
|
||||
/// PdfCraft patch (4): whether this level's bf entry for `code` was written with `byte_len`
|
||||
/// bytes (`<00fe>` is a two-byte code, not the one-byte `<fe>`), or doesn't record its length.
|
||||
/// Used where no codespace range gives the code its length.
|
||||
fn bf_code_has_length(&self, code: u32, byte_len: u8) -> bool {
|
||||
find_in_ranges(&self.bf_entries, code)
|
||||
.is_some_and(|entry| entry.code_len == 0 || entry.code_len == byte_len)
|
||||
}
|
||||
|
||||
/// PdfCraft patch (4): whether a code of `byte_len` bytes lies in a codespace range of that
|
||||
/// length (each byte within the range's bounds for its position, ISO
|
||||
/// 32000-2 §9.7.6.2). A CMap without codespace ranges defers to its base,
|
||||
/// and one with none anywhere allows every code.
|
||||
fn codespace_allows(&self, code: u32, byte_len: u8, depth: u32) -> bool {
|
||||
/// and with none anywhere the answer is `None`.
|
||||
fn codespace_allows(&self, code: u32, byte_len: u8, depth: u32) -> Option<bool> {
|
||||
if self._codespace_ranges.is_empty() {
|
||||
return match &self.base {
|
||||
Some(base) if depth < MAX_NESTING_DEPTH => {
|
||||
base.codespace_allows(code, byte_len, depth.saturating_add(1))
|
||||
}
|
||||
_ => true,
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
|
||||
self._codespace_ranges.iter().any(|range| {
|
||||
Some(self._codespace_ranges.iter().any(|range| {
|
||||
range.number_bytes == byte_len
|
||||
&& (0..u32::from(byte_len)).all(|i| {
|
||||
// `byte_len` is at most 4 here (the range's own length),
|
||||
@@ -492,7 +504,7 @@ impl CMap {
|
||||
let byte = |v: u32| v.checked_shr(shift).map_or(0, |b| b & 0xFF);
|
||||
byte(range.low) <= byte(code) && byte(code) <= byte(range.high)
|
||||
})
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
/// Look up a bf string in the cmap. This is usually
|
||||
@@ -620,6 +632,9 @@ impl PartitionedRanges {
|
||||
pub(crate) struct BfRange {
|
||||
pub(crate) range: Range,
|
||||
pub(crate) dst_base: Vec<u16>,
|
||||
/// PdfCraft patch (4): how many bytes the entry's source code was written with (1 to 4),
|
||||
/// or 0 where that isn't recorded (a binary CMap).
|
||||
pub(crate) code_len: u8,
|
||||
}
|
||||
|
||||
impl HasRange for BfRange {
|
||||
@@ -1226,10 +1241,33 @@ endbfchar
|
||||
// byte 0x20 is below 0x40.
|
||||
assert_eq!(cmap.lookup_cid_code(0x8220, 2), None);
|
||||
|
||||
let no_codespace = parse_without_codespace(b"1 beginbfchar <0020> <0020> endbfchar\n");
|
||||
let no_codespace = parse_without_codespace(b"1 beginbfchar <20> <0020> endbfchar\n");
|
||||
assert_eq!(no_codespace.lookup_cid_code(0x20, 1), Some(0x20));
|
||||
}
|
||||
|
||||
/// PdfCraft patch (4) test: without codespace ranges, a `bfchar` entry used as a CID
|
||||
/// mapping matches only codes of the length its source was written with, so the first
|
||||
/// byte of `<fe96>` is not taken for `<00fe>`.
|
||||
#[test]
|
||||
fn bfchar_cid_fallback_without_codespace_takes_the_source_length() {
|
||||
let cmap = parse_without_codespace(
|
||||
br#"
|
||||
2 beginbfchar
|
||||
<00fe> <0041>
|
||||
<fe96> <0042>
|
||||
endbfchar
|
||||
1 beginbfrange
|
||||
<0100> <0102> <0050>
|
||||
endbfrange
|
||||
"#,
|
||||
);
|
||||
assert_eq!(cmap.lookup_cid_code(0xfe, 1), None);
|
||||
assert_eq!(cmap.lookup_cid_code(0xfe96, 2), Some(0x42));
|
||||
assert_eq!(cmap.lookup_cid_code(0x00fe, 2), Some(0x41));
|
||||
assert_eq!(cmap.lookup_cid_code(0x0101, 2), Some(0x51));
|
||||
assert_eq!(cmap.lookup_cid_code(0x0101, 3), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stream_cut_off_inside_a_block_keeps_the_entries_before_it() {
|
||||
let cmap = parse_with_preamble(b"1 beginbfchar <41> <0058>\n<42> <00");
|
||||
|
||||
Vendored
+7
@@ -333,6 +333,8 @@ fn parse_bf_char<F>(
|
||||
let _ = scanner.parse_object();
|
||||
continue;
|
||||
};
|
||||
// PdfCraft patch (4): 1 to 4 (`extract_u32_code` checked).
|
||||
let code_len = u8::try_from(ctx.buf.len()).unwrap_or(0);
|
||||
let Ok(dst) = scanner.parse_string() else { continue };
|
||||
if dst.decode_into(&mut ctx.buf).is_err() { continue }
|
||||
let Some(dst_base) = decode_be(&ctx.buf) else { continue };
|
||||
@@ -343,6 +345,7 @@ fn parse_bf_char<F>(
|
||||
end: code,
|
||||
},
|
||||
dst_base,
|
||||
code_len,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -367,6 +370,8 @@ fn parse_bf_range<F>(
|
||||
let _ = scanner.parse_object();
|
||||
continue;
|
||||
};
|
||||
// PdfCraft patch (4): 1 to 4 (`extract_u32_code` checked).
|
||||
let code_len = u8::try_from(ctx.buf.len()).unwrap_or(0);
|
||||
let Some(end) = read_u32_code(scanner, &mut ctx.buf) else {
|
||||
// Skip the destination object as well to stay aligned.
|
||||
let _ = scanner.parse_object();
|
||||
@@ -383,6 +388,7 @@ fn parse_bf_range<F>(
|
||||
entries.push(BfRange {
|
||||
range: Range { start, end },
|
||||
dst_base,
|
||||
code_len,
|
||||
});
|
||||
}
|
||||
Object::Array(array) => {
|
||||
@@ -403,6 +409,7 @@ fn parse_bf_range<F>(
|
||||
end: code,
|
||||
},
|
||||
dst_base,
|
||||
code_len,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user