pdf-inspector icon indicating copy to clipboard operation
pdf-inspector copied to clipboard

Returning the color on PDF::Inspector::Text#font_settings

Open juan-ki opened this issue 1 year ago • 2 comments

When calling PDF::Inspector::Text#font_settings, it returns an array of objects with font name and size. I’d like to add the color of the text as well. From looking at the code, it seems these attributes are set here:

      def set_text_font_and_size(*params)
        @state.set_text_font_and_size(*params)
        @font_settings << { name: @fonts[params[0]], size: params[1] }
      end

If you agree that this would be a good addition, could you please advise on where to start in order to add this parameter?, I’d be happy to collaborate on a PR for this feature.

juan-ki avatar Oct 30 '24 21:10 juan-ki

I'm not against it in principle.

IIRC, set_text_font_and_size is a callback for PDF graphic stream command. There should be corresponding callbacks for commands for setting fill color (what is usually used for text color). You'd need to keep track of the current fill color to assign it to the text. You probably would also need to keep track of the drawing mode (e.g. fill only, outline only, etc.) because you probably can have fill color set but not actually used.

Study material:

  • PDF Reference
    • Either PDF Reference 1.7 (or ISO 32000-1:2008)
      • 4.4.2 Path-Painting Operators
      • 5: Text, and specifically:
        • 5.1.2 Achieving Special Graphical Effects
        • 5.2.5 Text Rendering Mode
    • Or PDF 2.0 (ISO 32000-2:2020)
      • 8.5.3: Path-painting operators
      • 9: Text, and specifically:
        • 9.2.3 Achieving special graphical effects
        • 9.3.6: Text Rendering Mode
  • PDF::Reader codebase

pointlessone avatar Oct 31 '24 09:10 pointlessone

I'll take a look, thanks

juan-ki avatar Nov 04 '24 18:11 juan-ki