Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous. You can also use this link to report any problems registering or logging in.

RT 33497 - PDF::API2::Outline::title() problem in using Unicode string

  • 2 Replies
  • 2216 Views
*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 437
    • View Profile
Subject:    PDF::API2::Outline::title() problem in using Unicode string
 
When setting Unicode string (use utf8;) in an outline title, that is
viewed broken.

I wrote code below to avoid problem.

*PDF::API2::Outline::title = sub {
    my $self = shift ;
    my $txt = shift;
    use PDF::API2::Basic::PDF::Utils;
    if( utf8::is_utf8( $txt ) ){
        $self->{Title}=PDFUtf($txt);
    }
    else {
        $self->{Title}=PDFStr($txt);
    }
    return($self);
};
#
Mon Apr 27 14:48:08 2009 otto.hirr [...] olabinc.com - Correspondence added
 
carried to PDF::API3 as https://rt.cpan.org/Ticket/Display.html?id=45489
#
Mon Apr 27 14:48:08 2009 The RT System itself - Status changed from 'new' to 'open'
« Last Edit: October 20, 2016, 07:15:53 PM by Phil »

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 437
    • View Profile
 PhilterPaper commented on Sep 29

It sounds like a more general solution might be to replace all PDF::Builder's hard-coded PDFStr (and PDFUtf) calls with a generic function call to check if the argument is utf8 or not, and return the appropriate call PDFStr or PDFUtf. What thinks the community? Is there a better way to handle this?

I would also be concerned about whether UTF-8-encoded text can be used in any particular situation, such as when using corefont or psfont, or perhaps with URLs.

Add: there's quite a few places in PDF::Builder where the string is checked to see if it's UTF-8, and to call PDFStr() or PDFUtf() accordingly, so such a function could be useful in streamlining code. There are also places where UTF-8 is evidently not allowed (URL strings, etc.), and utf8::downgrade() gets called -- this might be part of the function.

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 437
    • View Profile
Fixed by wrapping PDFStr and PDFUtf in PDFString call, with usage type. Will be in release 3.013.