Commit Graph

48 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
a855bce99b Initial plan 2026-01-25 12:19:56 +00:00
Kinneyzhang
06e28b078d add test 2026-01-25 20:12:38 +08:00
copilot-swe-agent[bot]
a421926e91 Fix C module single-box line handling order to match Elisp
Bug: C module and Elisp produced different results for same text.

Root cause: Different condition checking order for single-box vs last-line:
- Elisp: single-box check comes BEFORE is-last check
- C: is_last check came BEFORE is_single_box check (now fixed)

When the last line has only one box, Elisp uses single-box calculation
while C was using last-line calculation, resulting in different demerits
and different final breakpoints.

Fix: Moved is_single_box check before is_last check in dp_process_position()
to match Elisp's ekp--dp-compute-line-demerits behavior.

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 12:02:09 +00:00
copilot-swe-agent[bot]
4a84723181 Refactor C module to eliminate duplicate DP logic
Extracted shared DP core algorithm into dp_process_position() function:

1. Added dp_input_t struct - unified input interface for DP algorithm
   - Contains prefix arrays, glue arrays, hyphen info
   - Contains K-P parameters (penalties, ratios)

2. Added dp_is_hyphen() function - unified hyphen position detection
   - Uses O(log n) binary search
   - Replaces is_hyphen_pos() function

3. Added dp_process_position() function - core DP algorithm
   - Processes single start position i, tries all end positions k
   - Contains complete demerits calculation, fitness classification
   - Both entry functions now call this shared core

4. Refactored process_dp_range()
   - Builds temporary glue arrays from ekp_paragraph_t
   - Creates dp_input_t and calls dp_process_position()

5. Refactored ekp_break_with_prefixes()
   - Directly uses input arrays to create dp_input_t
   - Calls dp_process_position() for each position

Benefits:
- Single point of maintenance: DP bugs only need fixing once
- Consistency guaranteed: both paths use identical algorithm
- ~100 lines of duplicate code removed
- Better testability: core algorithm can be tested independently

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 11:55:27 +00:00
copilot-swe-agent[bot]
32021fbe35 Implement Looseness, Threshold Pruning, and Flagged Penalties
Feature 1: Looseness (Complete Implementation)
- Added alt-paths hash table to track alternative paths by (position, line-count)
- Modified DP loop to track all paths reaching each position
- ekp--dp-trace-breaks-with-looseness uses alt-paths to find closest match
- Added ekp--dp-trace-alt-path helper with safety limit

Feature 2: Threshold Pruning
- Added ekp-threshold-factor variable (default 0 = disabled)
- Paths with demerits > best × (1 + factor) are skipped
- Tracks best-end-demerits during DP for pruning decisions

Feature 3: Flagged Penalties (Forced Breaks)
- Added flagged-positions field to ekp-para struct
- Added ekp-flagged-penalty variable (negative = preferred)
- Added ekp--flagged-p with O(log n) binary search
- Modified DP to always accept flagged breaks

Tests:
- ekp-test-unit--hyphenate-p-binary-search
- ekp-test-unit--flagged-p-binary-search
- ekp-test-unit--alt-paths-hash
- ekp-test-unit--threshold-factor
- ekp-test-unit--flagged-penalty
- Updated ekp-test-unit--struct-access for new fields

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 11:35:30 +00:00
copilot-swe-agent[bot]
b70affb9ef Optimize hyphen position lookup O(n)->O(log n) and add named constants
Performance:
- ekp--hyphenate-p: O(n) cl-find -> O(log n) binary search
- is_hyphen_break: O(n) linear -> O(log n) binary search
- is_hyphen_pos: O(n) linear -> O(log n) binary search

In O(n²) DP loop, this reduces worst-case complexity from O(n³) to O(n² log n)

Code quality:
- Add ekp-consecutive-hyphen-penalty (was hardcoded 100)
- Add ekp-forced-break-penalty (was hardcoded 10000)
- Add ekp-last-line-short-penalty (was hardcoded 50)
- Update ekp-looseness docstring noting partial implementation

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 11:15:42 +00:00
copilot-swe-agent[bot]
fb58a9b19a Fix remaining global glue param usages in DP and glue distribution functions
Code review found additional functions using global glue params instead
of para's stored params:
- ekp--compute-stretch-capacity: now takes para param
- ekp--compute-shrink-capacity: now takes para param
- ekp--line-badness-and-fitness: now takes para param
- ekp--dp-compute-line-demerits: now takes para param
- ekp--distribute-gap-adjustment: now takes para param

All capacity/distribution calculations now use para's stored glue params
for full consistency across multi-font paragraphs.

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 11:03:27 +00:00
copilot-swe-agent[bot]
333618bb57 Fix glue parameter caching inconsistency for multi-font paragraphs
When multiple paragraphs with different fonts were processed, subsequent
executions would use wrong glue parameters from the cache. This caused
misalignment because different fonts have different spacing values.

Changes:
- Add glue-params field to ekp-para struct to store params at creation
- Add helper functions: ekp--para-glue-ideal/shrink/stretch/min/max
- Update all C module interface functions to use para's stored params
- Update all glue computation functions for consistency

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 10:52:45 +00:00
copilot-swe-agent[bot]
fee05f769d Fix C module to match Elisp behavior for last-line overflow handling
When is_last && ideal > line_width, the C module now correctly
triggers force break logic, matching ekp--dp-cache-elisp behavior.
This ensures consistent results between C module and pure Elisp paths.

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2026-01-25 10:32:06 +00:00
copilot-swe-agent[bot]
b296de0928 Initial plan 2026-01-25 10:25:46 +00:00
Kinneyzhang
a790aa87c3 update 2026-01-25 18:23:33 +08:00
Kinneyzhang
68ca9b191a improve C module parallel 2026-01-25 17:28:04 +08:00
Kinneyzhang
6cf6f75f71 fix bugs of C moudule 2026-01-25 16:53:23 +08:00
Kinneyzhang
aaeea099c9 fix bug 2026-01-25 15:11:47 +08:00
Kinneyzhang
c88bbdd395 add dynamic moudle to improve prefermance 2026-01-25 13:50:46 +08:00
Kinneyzhang
91d9bbc1e9 process spaces between words 2026-01-25 01:17:18 +08:00
Kinneyzhang
6cf17e0066 update knuth-plass paper link 2026-01-24 22:46:48 +08:00
Kinneyzhang
6421f6b1fb refactor ekp cache and code improve 2026-01-24 22:40:53 +08:00
Kinneyzhang
68b46f8337 code improve 2026-01-24 20:44:38 +08:00
copilot-swe-agent[bot]
dab9ca280e Add optional use-cache parameter to ekp-pixel-justify and ekp-pixel-range-justify
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2025-11-29 17:56:42 +00:00
copilot-swe-agent[bot]
c4240fe15c Initial plan 2025-11-29 17:54:24 +00:00
copilot-swe-agent[bot]
f56ec5a520 Fix ekp-text-hash to consider text properties
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
2025-11-29 17:09:16 +00:00
copilot-swe-agent[bot]
5c646bf6be Initial plan 2025-11-29 17:06:09 +00:00
Kinneyzhang
ca9349e99f fix bug when text is blank string 2025-09-26 00:18:37 +08:00
Kinneyzhang
820e73920a update test 2025-08-22 00:15:33 +08:00
Kinneyzhang
37baccded8 keep original text properties of string after typesetting 2025-08-22 00:06:14 +08:00
Kinneyzhang
165be829df a batter ekp-cjk-char-p 2025-08-19 11:31:48 +08:00
Kinneyzhang
796d3e49d2 misc 2025-08-18 00:35:40 +08:00
Kinneyzhang
12b5029bbf update readme_zh 2025-08-09 19:32:23 +08:00
Kinneyzhang
3df885bef8 Merge branch 'main' of github.com:Kinneyzhang/emacs-kp 2025-08-09 19:30:12 +08:00
Kinneyzhang
28d6c8ee77 fix bug in ekp-hyphen-str 2025-08-09 19:29:07 +08:00
Kinneyzhang
3d1e975878 update readme 2025-07-31 10:51:39 +08:00
Kinneyzhang
b6ee3dedcc fix bug when a line only has one word ends with hyphen 2025-07-29 15:43:23 +08:00
Kinneyzhang
564f33ba27 fix issue #1 2025-07-28 19:45:40 +08:00
Kinneyzhang
4facde5235 Merge branch 'main' of github.com:Kinneyzhang/emacs-kp 2025-07-28 17:19:27 +08:00
Kinneyzhang
b64975e295 add Next Todos 2025-07-28 17:17:21 +08:00
Kinneyzhang
c6fb8743bb add Next Todos 2025-07-28 17:15:57 +08:00
Kinneyzhang
eb78e5316f fix _ local variable bug 2025-07-28 16:58:30 +08:00
Kinneyzhang
b6f6616b81 add chinese example 2025-07-28 00:33:53 +08:00
Kinneyzhang
41bbcf2a69 update readme 2025-07-27 22:56:51 +08:00
Kinneyzhang
ceae5f12c2 update readme 2025-07-27 22:37:55 +08:00
Kinneyzhang
e8a35f1fac update readme 2025-07-27 22:35:49 +08:00
Kinneyzhang
e9b36312fb update readme 2025-07-27 22:33:28 +08:00
Kinneyzhang
6efd1985d1 update readme 2025-07-27 21:53:46 +08:00
Kinneyzhang
f88b4173f7 update readme 2025-07-27 21:41:39 +08:00
Kinneyzhang
890a3cfe97 update readme 2025-07-27 21:39:47 +08:00
Kinneyzhang
a265357e41 update readme 2025-07-27 21:35:44 +08:00
Kinneyzhang
f7f1f7104c first commit 2025-07-26 23:52:04 +08:00