Skip to content

Commit

Permalink
Position coincident page marks in the correct order (#1274)
Browse files Browse the repository at this point in the history
* Position coincident page marks in the correct order

If Pg123 and Pg124 were at the same location in the file,
usually because Pg123 is blank, then when the page locations
are loaded from the bin file and positioned in the text widget
using "marks", the mark for Pg124 was inserted at the location
where Pg123's mark was, and ended up before it in the text
widget's internal list of marks.

Loading the marks in reverse order means that coincident
marks appear in alphanumeric order,  which is preferable.

This was assumed to be the case by the HTML generation
code when set to skip coincident pagenum spans. So this
fixes #1272

* Revert "Position coincident page marks in the correct order"

This reverts commit f366b5e.

* Sort pagemarks correctly when adding HTML pagenums

Although `markNext` iterates through the marks in order of their
location, it does not guarantee an order when two marks have the
same location. This could lead to some page numbers that directly
followed blank pages not being output to the HTML file.

To resolve it, just sort a list of page markers and use that, rather
than iterating through the markers in the file.

Fixes #1272
  • Loading branch information
windymilla authored Nov 19, 2023
1 parent a0ff105 commit 4de77c1
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/lib/Guiguts/HTMLConvert.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1250,20 +1250,19 @@ sub html_convert_sidenotes {
sub html_convert_pageanchors {
my $textwindow = $::textwindow;
::working("Inserting Page Number Markup");
$|++;
my @pagerefs; # keep track of first/last page markers at the same position
my $tempcounter;
my $mark = '1.0';
while ( $textwindow->markPrevious($mark) ) {
$mark = $textwindow->markPrevious($mark);
}

my $closure = voidclosure();

# Work through all the text markers
while ( $mark = $textwindow->markNext($mark) ) {
next unless $mark =~ m{Pg(\S+)}; # Only look at page markers
my $markindex = $textwindow->index($mark); # Get page marker's index
# Get a correctly sorted list of page markers - if two markers are at the
# same location, the order returned by markNext is not defined, but we need
# them ordered by png.
my @pagemarklist = sort grep ( /^Pg\S+$/, $textwindow->markNames );

for my $idx ( 0 .. $#pagemarklist ) {
my $mark = $pagemarklist[$idx];
my $markindex = $textwindow->index($mark); # Get page marker's index
my $marknext = $idx < $#pagemarklist ? $pagemarklist[ $idx + 1 ] : "";

# This is the custom page label
my $num = $::pagenumbers{$mark}{label};
Expand All @@ -1283,12 +1282,6 @@ sub html_convert_pageanchors {
push @pagerefs, $num;
}

# Find next page marker & its index
my $marknext = $mark;
while ( $marknext = $textwindow->markNext($marknext) ) {
last if $marknext =~ m{Pg(\S+)};
}

# If no more marks (reached end of file) or there are word characters between the
# current mark and the next, then convert batch of accumulated page markers to a string
my $pagereference = '';
Expand Down

0 comments on commit 4de77c1

Please sign in to comment.