deri pushed a commit to branch master
in repository groff.

commit f336f8244b09191b16722984c33fc5addcc4a284
Author: Deri James <d...@chuzzlewit.myzen.co.uk>
AuthorDate: Tue Apr 16 17:34:59 2024 +0100

    Problem with '(' and '\' (\[rs])
    
    Bpth these tokens have meaning for roff AND pdf strings. In
    pdfs unbalanced parentheses have to be escaped (with '\') and
    a single '\' has to be similarly escaped, '\\'. It is gropdf's
    responsibility to ensure pdf strings are valid, no matter what
    the input.
    
    If '\(ul' is passed then the UTF-16 character becomes '_'.
    If '\[rs](ul' is passed (i.e. '\(ul' is intended to become the
    UTF-16 string) \[rs] becomes '\' leaving '\(ul', which if
    becomes '_', not what is intended. If the unbalanced '(' is
    eascaped first, '\[rs]\(ul' which could become '\\_' when the
    '\' is escaped, yielding '\_'. The code which escpes parenthesis
    checks it is not already preceded by '\' since adding another
    would give you '\\(' which is not what you want. The correct
    output should be '\\\(ul' to achieve the correct pdf string.
    
    This fixes the above issue (I hope).
    
    * src/devices/gropdf/gropdf.pl: Change pattern matches
---
 src/devices/gropdf/gropdf.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
index 3ca187f69..5543b0f1f 100644
--- a/src/devices/gropdf/gropdf.pl
+++ b/src/devices/gropdf/gropdf.pl
@@ -1981,7 +1981,6 @@ sub Clean
     my $p=shift;
 
     $p=~s/\\c?$//g;
-    $p=~s/\\[eE]/\\/g;
     $p=~s/\\[ 0~t]/ /g;
     $p=~s/\\[,!"#\$%&’.0:?{}ˆ_‘|^prud]//g;
     $p=~s/\\'/\\[aa]/g;
@@ -2004,6 +2003,7 @@ sub utf16
     my $p=Clean(shift);
     my $label=shift;
 
+    $p=~s/\\\(rs|\\\[rs\]/\\E/g;
     $p=~s/\\\[(.*?)\]/FindChr($1,0)/eg;
     $p=~s/\\C($parcln)/FindChr($1,1)/eg;
 #    $p=~s/\\\((..)/FindChr($1)/eg;
@@ -2019,6 +2019,7 @@ sub utf16
 
     $p=~s/(?<!\\)\(/\\\(/g;
     $p=~s/(?<!\\)\)/\\\)/g;
+    $p=~s/\\[eE]/\\\\/g;
 
     return($p);
 }

_______________________________________________
Groff-commit mailing list
Groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to