[ 
https://issues.apache.org/jira/browse/PDFBOX-4975?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17205546#comment-17205546
 ] 

Richard edited comment on PDFBOX-4975 at 10/1/20, 2:15 PM:
-----------------------------------------------------------

bq. could you outline how you did change PDPageContentStream and how you check 
if a font is suitable for a specific character?

Sure this is what I've done
* Create a class that extends {{PDFont}}, say {{PDFontList}}, which is mainly 
meant to be a container for a list of fonts
* In {{PDPageContentStream}}, when {{setFont}} is called, check if it's a 
{{PDFontList}} and if it is, set it on the {{fontStack}}, set the size (in the 
{{PDFontList}} object) and early return
* Also in {{PDPageContentStream}}, when {{showTextInternal}} is called, check 
if it's a {{PDFontList}}, if it is then
** For each character in the text
*** For each font
**** Try to encode the character using the font, if it works then call 
{{setFont}} and {{showText}} and early return from this for loop (going to the 
next character)
* At the end call {{setFont}} with the {{PDFontList}} and early return

So you create an instance of {{PDFontList}} with the fonts you want and set 
{{PDPageContentStream}} to use this font. Then anything using this instance, 
calling its {{PDPageContentStream.showText}} or 
{{PDPageContentStream.showTextWithPositioning}} will automatically try all 
fonts.

{{PDFontList}} also has a font descriptor and a few methods which return the 
max/min value of the fonts it has (e.g. max ascent) but I just set those as I 
needed them.


was (Author: mealing):
bq. could you outline how you did change PDPageContentStream and how you check 
if a font is suitable for a specific character?

Sure this is what I've done
* Create a class that extends {{PDFont}}, say {{PDFontList}}, which is mainly 
meant to be a container for a list of fonts
* In {{PDPageContentStream}}, when {{setFont}} is called, check if it's a 
{{PDFontList}} and if it is, set it on the {{fontStack}}, set the size (in the 
{{PDFontList}} object) and early return
* Also in {{PDPageContentStream}}, when {{showTextInternal}} is called, check 
if it's a {{PDFontList}}, if it is then
** For each character in the text
*** For each font
**** Try to encode the character using the font, if it works then call 
{{setFont}} and {{showText}} and early return from this for loop (going to the 
next character)
* At the end call {{setFont}} with the {{PDFontList}} and early return

So you create an instance of {{PDFontList}} with the fonts you want and set 
{{PDPageContentStream}} to use this font. Then anything using this instance, 
calling its {{PDPageContentStream.showText}} or 
{{PDPageContentStream.showTextWithPositioning} } will automatically try all 
fonts.

{{PDFontList}} also has a font descriptor and a few methods which return the 
max/min value of the fonts it has (e.g. max ascent) but I just set those as I 
needed them.

> Make PDPageContentStream non-final 
> -----------------------------------
>
>                 Key: PDFBOX-4975
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4975
>             Project: PDFBox
>          Issue Type: Wish
>            Reporter: Richard
>            Priority: Major
>
> Currently {{PDPageContentStream}} is final.
> There are some situations where it would be useful to define our own 
> {{PDPageContentStream}}.
> For example, in my use-case I want to be able to try multiple fonts in case 
> the characters in the text are not all in one font. The library I'm using 
> accepts {{PDPageContentStream}} instances, so it would be much easier to pass 
> a subclass of {{PDPageContentStream}} with the desired behavior rather than 
> overhaul the library itself.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to