Yes, I also noticed that. The mistake is that PdfFont is stateful: it
should be stateless instead and state, e.g. font size, should be moved
to PdfPainter or other classes using PdfFont. Sometimes  code quality
of PoDoFo is very awkward as such mistakes can't be fixed without
breaking API.
On Fri, 16 Nov 2018 at 17:57, Michal Sudolsky <sudols...@gmail.com> wrote:
>
> Fonts created for different documents should be independent. In other case 
> you cannot do anything usable with them when using multiple threads.
>
> Code:
> ``` c++
> PdfMemDocument doc0;
> PdfFont *font0 = doc0.CreateFont("Helvetica");
> font0->SetFontSize(10);
>
> PdfMemDocument doc1;
> PdfFont *font1 = doc1.CreateFont("Helvetica");
> font1->SetFontSize(20);
>
> printf("font0 size %g\n", font0->GetFontSize());
> printf("font1 size %g\n", font1->GetFontSize());
> ```
>
> Output:
> ```
> font0 size 20
> font1 size 20
> ```
>
> What I would expect (or what happens when is font for example "Arial"):
> ```
> font0 size 10
> font1 size 20
> ```
>
> Fonts font0 and font1 are different objects but they share same m_pMetrics 
> (in case of base 14 fonts) which is used for font size and other font 
> settings. This is because PODOFO_Base14FontDef_FindBuiltinData is returning 
> mutable pointer to static global array PODOFO_BUILTIN_FONTS.
>
> This is here probably from beginning.
>
> I am sending patch. Hopefully I did not forget something. 
> PODOFO_Base14FontDef_FindBuiltinData is now returning newly allocated metrics 
> object copy constructed from PODOFO_BUILTIN_FONTS[i]. I deleted destructor of 
> PdfFontTypeBase14 so metrics object is properly deleted with font. I also 
> changed PODOFO_BUILTIN_FONTS to const for sure that there is nothing else 
> that changes it.
>
> _______________________________________________
> Podofo-users mailing list
> Podofo-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/podofo-users


_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to