Bug 105772 - [PATCH] Arthur support for Type3 fonts
Summary: [PATCH] Arthur support for Type3 fonts
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: arthur backend (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-27 19:54 UTC by oliver.sander
Modified: 2018-04-11 17:41 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
Patch that prevents 'startPage' to fill the page with white color (1.40 KB, patch)
2018-03-27 19:54 UTC, oliver.sander
Details | Splinter Review
Patch that implements type3 font support in Arthur backend (9.43 KB, patch)
2018-03-27 19:56 UTC, oliver.sander
Details | Splinter Review
Patch that implements type3 font support in Arthur backend (9.88 KB, patch)
2018-04-07 20:28 UTC, oliver.sander
Details | Splinter Review

Description oliver.sander 2018-03-27 19:54:23 UTC
Created attachment 138383 [details] [review]
Patch that prevents 'startPage' to fill the page with white color

I implemented type3 font support in the Arthur backend, loosely following what the Cairo backend does.  It's a prototype and needs more testing, but unfortunately I have only a few documents with type3 fonts.

I'll upload two patches:
1) The first removes code that made the startPage method fill the page with white color.  It is unclear why this code existed at all.  For type3 fonts it is problematic because then glyphs can have a white background, rather than a transparent one.

2) The actual implementation.  It is as short as I could make it, but the result is not as pretty as could be.  For example, there are now two separate caches for type3 fonts and other fonts.  I think the best would be to introduce an abstract ArthurFont base class, and an ArthurFontEngine.cc file similar to what the Cairo backend does.  I'll promise to provide this as a separate cleanup patch once the type3 support has been merged.
Comment 1 oliver.sander 2018-03-27 19:56:29 UTC
Created attachment 138384 [details] [review]
Patch that implements type3 font support in Arthur backend
Comment 2 oliver.sander 2018-03-27 20:20:26 UTC
I forgot to mention: this needs the implementation of drawImageMask from

  https://bugs.freedesktop.org/show_bug.cgi?id=105531

to work.
Comment 3 Albert Astals Cid 2018-04-02 10:20:10 UTC
- Why white?  Why not any other color?

Because the code is buggy 

- Apparently the method is rarely called: The renderToArthur method
  in file poppler-page.cc, for example, does not call it.

Are you sure about that? renderToArthur calls displayPageSlice that calls displaySlice that calls createGfx that calls Gfx constructor with pagenum that calls startPage

- Most importantly: We want to use ArthurOutputDev to render type3
  glyphs.  But they should have a transparent background, or rather,
  no background at all.

I don't understand this reasoning.
Comment 4 oliver.sander 2018-04-05 20:24:23 UTC
>> - Why white?  Why not any other color?
> Because the code is buggy 

I'd happily try to fix the code, if somebody tells me what the startPage method is supposed to do.

>> - Apparently the method is rarely called: The renderToArthur method
>>   in file poppler-page.cc, for example, does not call it.

> Are you sure about that? renderToArthur calls displayPageSlice that calls displaySlice that calls createGfx that calls Gfx constructor with pagenum that calls startPage

Well, I said 'rarely', not 'never'. :-)  In particular, I had to make the renderToImage method fill the page with the page color, to get a background at all (in 7e844eae94bc4eda1c6dcc3460840b25f4ca7898) The code in startPage didn't seem to have any effect.  But I readily admit that I was never quite sure what the proper location is for the code that initializes the page background.

Tangentially related: What is the precise meaning of the IgnorePaperColor flag?  Does it mean 'make the background transparent'?

>> - Most importantly: We want to use ArthurOutputDev to render type3
>>  glyphs.  But they should have a transparent background, or rather,
>>  no background at all.

> I don't understand this reasoning.

The type3 code in the attached patch is partially cargo-culted from the cairo backend.  It creates new ArthurOutputDev and Gfx objects for each glyph, and uses them to render a single glyph into a QPicture.  The cairo backend calls startPage on the output device, which in the case of the ArthurOutputDev leads to the effect that each glyph has a white rectangular background.  You will notice that when rendering type3 text on a non-white background.
Comment 5 Albert Astals Cid 2018-04-05 22:01:21 UTC
(In reply to oliver.sander from comment #4)
> >> - Why white?  Why not any other color?
> > Because the code is buggy 
> 
> I'd happily try to fix the code, if somebody tells me what the startPage
> method is supposed to do.

To be honest i don't think there's a definition of what is supposed to do other than "do the things that you need to do when starting a new page"

> 
> >> - Apparently the method is rarely called: The renderToArthur method
> >>   in file poppler-page.cc, for example, does not call it.
> 
> > Are you sure about that? renderToArthur calls displayPageSlice that calls displaySlice that calls createGfx that calls Gfx constructor with pagenum that calls startPage
> 
> Well, I said 'rarely', not 'never'. :-)  

I don't understand this, you said "renderToArthur method in file poppler-page.cc, for example, does not call it." and i showed you that it does.

> In particular, I had to make the
> renderToImage method fill the page with the page color, to get a background
> at all (in 7e844eae94bc4eda1c6dcc3460840b25f4ca7898) The code in startPage
> didn't seem to have any effect.  But I readily admit that I was never quite
> sure what the proper location is for the code that initializes the page
> background.
> 
> Tangentially related: What is the precise meaning of the IgnorePaperColor
> flag?  Does it mean 'make the background transparent'?

Yes, i'd say you awnt to hide that tmpimg.fill(bgColor); inside a check for not IgnorePaperColor

> >> - Most importantly: We want to use ArthurOutputDev to render type3
> >>  glyphs.  But they should have a transparent background, or rather,
> >>  no background at all.
> 
> > I don't understand this reasoning.
> 
> The type3 code in the attached patch is partially cargo-culted from the
> cairo backend.  It creates new ArthurOutputDev and Gfx objects for each
> glyph, and uses them to render a single glyph into a QPicture.  The cairo
> backend calls startPage on the output device, which in the case of the
> ArthurOutputDev leads to the effect that each glyph has a white rectangular
> background.  You will notice that when rendering type3 text on a non-white
> background.

I see.
Comment 6 oliver.sander 2018-04-07 20:28:56 UTC
Created attachment 138679 [details] [review]
Patch that implements type3 font support in Arthur backend

Updated the patch: The old patch didn't to the text matrix transformation, and therefore misrendered the example file from 105531 ( https://bugs.freedesktop.org/attachment.cgi?id=138385 )
Comment 7 Albert Astals Cid 2018-04-08 11:14:31 UTC
a quick regtest look says It is a definite improvement, so i can commit it if you want. 

*BUT* it still has bugs, page 281 of http://caml.inria.fr/pub/docs/oreilly-book/ocaml-ora-book.pdf shows the hatched parts totally back when it should be only some diagonal bars.

Your call, do you want to try to fix that first or should i commit this?
Comment 8 oliver.sander 2018-04-08 11:26:37 UTC
Let me have a look at that bug first.

There is also the open question whether an alternative implementation using beginType3Char/endType3Char could be simpler and faster.  Should I give that a try, too?  I am undecided.
Comment 9 Albert Astals Cid 2018-04-10 22:46:26 UTC
Shit, i pushed the patch by mistake :( Sorry

Want me to revert it?

To be honest i don't know enough about type3 to be able to suggest what's a better implementation
Comment 10 oliver.sander 2018-04-11 07:07:26 UTC
Keep the patch---you said it is a definite improvement.

- I may look at alternative implementations, but my motivation is independent of whether this patch is submitted or not.

- I had a quick look at the problem with the ocaml book.  I could probably fix it, but I am low on time for a few months now, so let's track that in a separate bug report.
Comment 11 Albert Astals Cid 2018-04-11 17:41:10 UTC
Ok, closing this then and let's track the other in a different place :)


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.