handle other alignments alongside "J" in UTF8 CellFormat #105
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
go-pdf/fpdf!105
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "JaredReisinger/fpdf:104-justified-utf8"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The "J" justification handling in CellFormat() was an equality test, not a
strings.Contains()check (like the others), and therefore it was only succeeding on a "J" with no other (vertical) alignment.This changes that check to
strings.Contains()and adds a test that verifies that the justification codepath is executed even for an alignment like "JA".Fixes #104
dyoffset calculation 6c81fcf0eehi,
thanks for your interest in
fpdfand for tackling this.I have a couple of minor comments.
see below.
@ -329,0 +349,4 @@//// BT 31.19 785.17 Td (This is justified-baseline text.)Tj ET//// If is *is* justified, well get placement of individual words:🤦, thanks for catching the typo!
@ -329,0 +369,4 @@// we're getting to the correct codepath.// pattern := regexp.MustCompile(`\nBT 0 Tw .* Td \[\(This\) .* \(is\) .* \(justified-baseline\) .* \(text.\) ] TJ ET\n`)pattern := regexp.MustCompile(`\bBT 0 Tw .* Td \[\(`)couldn't we just look for the exact string
BT 0 Tw 31.19 796.37 Td [(This) -4870.000( ) (is) -4870.000( ) (justified-baseline) -4870.000( ) (text.) ] TJ ETinstead ?surely the PDF production is reproducible, right ?
What I wasn't sure about, since this was my first foray into
fpdf, was whether running on different machines might have slight differences in the low-order bits of the float64. I was erring on the side of "don't make the test overly fragile". If you think an exact string match won't be too fragile, I'm happy to change it to that. 😊the original
fpdfcode (and this one still) was actually comparing bytes-for-bytes equality with reference files:https://codeberg.org/go-pdf/fpdf/src/branch/main/internal/example/example.go#L132
so I think we can go the exact string match. (and adapt later on if stringified floating-point comparison bites us later on in the game).
looking at the produced PDF, I figured out why the "full" regexp doesn't match. The PDF actually contains:
so I'd suggest the following test:
@ -329,0 +349,4 @@//// BT 31.19 785.17 Td (This is justified-baseline text.)Tj ET//// If is *is* justified, we'll get placement of individual words:there were actually 2 typos :)
(
s/If is/If it/)🤦♂️... fixed!
I also ran into this issue today (justify is ignored if any vertical alignment is set).
From the history of this pull request, it looks like the fix is simple; but it has not been applied because the test function was not completed.
Is there something left to be done on the test? Or is the fix not as straightforward as it seems?
it was just a case of me dropping the ball.
apologies to @JaredReisinger .
Awesome - thank you very much!
One less workaround to keep :)