Closed ericsprauve closed 4 years ago
In your line
aliasUtf16 := utf8toutf16(f.aliasNbPagesStr, false)
did you mean
aliasUtf16 := utf8toutf16(alias, false)
It seems to me a utf8toutf16()
conversion also required in the replaceAliases()
function.
test
You're correct, that was a typo on my part. I've corrected it in the latest push.
Since the only function that modifies f.aliasMap
is RegisterAlias
, my assumption is that if we encode and store both the UTF8 and UTF16 in the register function, then we wouldn't need to modify replaceAliases
since replaceAliases
pulls from f.aliasMap
(which will have both encodings).
Thanks, @ericsprauve. I think this change warrants a test, preferably an example test. Can you modify ExampleFpdf_RegisterAlias()
in fpdf_test.go. Instead of
pdf.SetFont("Arial", "", 12)
you will load the included UTF-8 font as follows:
pdf.AddUTF8Font("dejavu", "BI", example.FontFile("DejaVuSansCondensed-BoldOblique.ttf"))
pdf.SetFont("dejavu", "BI", 12)
Run make cov
to run the tests. This will generate documents in the pdf directory.
Thanks @jung-kurt, I just added the example test to the test suite and verified that the alias was correctly registered.
Thanks for your work on this, @ericsprauve. I dug further into the alias replacement operation and found that strings that were converted with utf8toutf16()
prior to assignment into the alias map caused the later replacement logic to fail. (UTF-16 strings in maps unexpectedly contain literal escape sequences.) Instead, the utf8toutf16()
conversion is now deferred until the actual search-and-replace operation. Aliases with both UTF-8 and non-UTF-8 fonts are now demonstrated. These changes were commited in b1657c7960b94f9c1f90fa1efaf49e04f78e0f91 so your PR will be closed.
Move the UTF16 conversion into RegisterAlias to allow external alias registration to support UTF16.