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>
This commit is contained in:
parent
4a84723181
commit
a421926e91
@ -275,7 +275,20 @@ static void dp_process_position(
|
||||
uint8_t fit;
|
||||
double dem;
|
||||
|
||||
if (is_last) {
|
||||
/* Single-box line: use fixed flexibility=1, fitness=decent
|
||||
* This must come BEFORE is_last check to match Elisp behavior
|
||||
* where single-box lines use consistent calculation */
|
||||
if (is_single_box) {
|
||||
badness = compute_badness(adjustment, 1);
|
||||
fit = FITNESS_DECENT;
|
||||
|
||||
int penalty = end_hyphen ? in->hyphen_penalty : 0;
|
||||
dem = prev_dem + compute_demerits(badness, penalty,
|
||||
prev_fit, fit,
|
||||
end_hyphen, prev_hyph,
|
||||
in->line_penalty,
|
||||
in->fitness_penalty);
|
||||
} else if (is_last) {
|
||||
/* Last line: minimal penalty if reasonably filled */
|
||||
double fill_ratio = (double)ideal / line_width;
|
||||
if (fill_ratio < in->last_line_ratio) {
|
||||
@ -286,17 +299,6 @@ static void dp_process_position(
|
||||
fit = FITNESS_DECENT;
|
||||
dem = prev_dem + (in->line_penalty + badness) *
|
||||
(in->line_penalty + badness);
|
||||
} else if (is_single_box) {
|
||||
/* Single-box line: use fixed flexibility=1, fitness=decent */
|
||||
badness = compute_badness(adjustment, 1);
|
||||
fit = FITNESS_DECENT;
|
||||
|
||||
int penalty = end_hyphen ? in->hyphen_penalty : 0;
|
||||
dem = prev_dem + compute_demerits(badness, penalty,
|
||||
prev_fit, fit,
|
||||
end_hyphen, prev_hyph,
|
||||
in->line_penalty,
|
||||
in->fitness_penalty);
|
||||
} else {
|
||||
badness = compute_badness(adjustment, flexibility);
|
||||
fit = compute_fitness(adjustment, flexibility);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user