This is just starter - what I would try to do first from curiosity as I
suppose it may actually work in certain circumstances. There may be needed
some additional mapping or other things. For correctly doing this I would
read for example something about CID Fonts and other things about fonts in
pdf (I did not research this much).

On Thu, Feb 27, 2020 at 5:18 PM Michal Sudolsky <sudols...@gmail.com> wrote:

> Hi,
>
> This podofo thread may be useful:
> https://sourceforge.net/p/podofo/mailman/message/32419281/
>
> So suppose font was added to pdf either by podofo api or manually as
> described there if needed.
>
> You can get glyph ids and positions using HarfBuzz:
>
> 1. You may not be able to use PdfPainter api like DrawText or AddText
> because they all handle unicode strings unless you somehow bypass this and
> makes them accept glyph ids. But character positions may be incorrect
> unless you draw individual glyphs into positions from HarfBuzz.
>
> 2. Glyph ids from HarfBuzz should be what is expected in PDF drawing
> instructions like "Tj" without PdfPainter. You can follow what is doing
> SetPage and DrawText in PdfPainter. First get PdfStream of page contents
> like in SetPage "pdf.GetPage(n)->GetContentsForAppending()->GetStream()".
> Call BeginAppend then Append whitespace and text operators and call
> EndAppend. Like DrawText use operators like this:
>
> BT
> /font_id font_size Tf
> position_x position_y Td
> <glyph_id_or_ids_as_hex> Tj
> ET
>
> For example like this with single glyph id 0xAF12 and two glyphs 0x1234
> and 0xABCD (in pdf endian):
>
> BT
> /Ft14 24 Tf
> 10 20 Td
> <AF12> Tj
> 30 40 Td
> <1234ABCD> Tj
> ET
>
> You may need to read pdf reference about graphics state operators. If I am
> not wrong "Td" uses relative coordinates so you may little play how to use
> HarfBuzz offsets and "advance" based on their example. For correct
> positioning you may need to draw each glyph individually or check "TJ"
> which allows individual horizontal glyph positioning.
>
> On Thu, Feb 27, 2020 at 2:02 PM Anand Ramasamy <ramasam...@hcl.com> wrote:
>
>> Dear Michal,
>>
>>
>>
>> Thank you for your help in advance.
>>
>>
>>
>> We were able to generate the glyphs and shape it using HarfBuzz libraries.
>>
>>
>>
>> Is there any way to write the generated glyphs as text in PDF document
>> using PoDoFo library?
>>
>>
>>
>> Regards,
>>
>> Anand.
>>
>> *From:* Anand Ramasamy
>> *Sent:* Thursday, February 13, 2020 9:26 PM
>> *To:* Michal Sudolsky <sudols...@gmail.com>
>> *Cc:* podofo-users@lists.sourceforge.net
>> *Subject:* RE: [Podofo-users] Arabic characters not displayed properly
>> when AddText API is used.
>>
>>
>>
>> Dear Michal,
>>
>>
>>
>> Sorry for the delayed reply.
>>
>>
>>
>> Please let me  know whether there are any chances for Arabic fonts to be
>> supported by Podofo library in future.
>>
>>
>>
>> Regards,
>>
>> Anand.
>>
>> *From:* Michal Sudolsky <sudols...@gmail.com>
>> *Sent:* Monday, November 18, 2019 7:48 PM
>> *To:* Anand Ramasamy <ramasam...@hcl.com>
>> *Cc:* podofo-users@lists.sourceforge.net
>> *Subject:* Re: [Podofo-users] Arabic characters not displayed properly
>> when AddText API is used.
>>
>>
>>
>> I am getting PdfError at "PdfString str1( ar.c_str() );":
>>
>>
>>
>> PoDoFo encountered an error. Error: 8 ePdfError_InternalLogic
>> Error Description: An internal error occurred.
>> Callstack:
>> #0 Error Source: podofo/base/PdfString.cpp:171
>>
>>
>>
>> My guess is that in order to join these characters you would need to do
>> kerning (https://en.wikipedia.org/wiki/Kerning
>> <https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FKerning&data=02%7C01%7Cramasamy-a%40hcl.com%7C451e8dcbe7b14a7d067b08d76c3216ed%7C189de737c93a4f5a8b686f4ca9941912%7C0%7C0%7C637096834699540974&sdata=dOFcg52fEIhHr7EPlaVs84Bbbce0fOrpeSAlCq%2BKKKs%3D&reserved=0>)
>> or use ligatures/alternates (
>> https://en.wikipedia.org/wiki/Orthographic_ligature
>> <https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FOrthographic_ligature&data=02%7C01%7Cramasamy-a%40hcl.com%7C451e8dcbe7b14a7d067b08d76c3216ed%7C189de737c93a4f5a8b686f4ca9941912%7C0%7C0%7C637096834699540974&sdata=TNtzRAY1FtjOhi%2FVqzGh6NOR%2FjlNjxSH6Y478zdfhww%3D&reserved=0>).
>> From my observation podofo does not support these things:
>>
>>
>>
>> https://sourceforge.net/p/podofo/mailman/message/36260915/
>> <https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsourceforge.net%2Fp%2Fpodofo%2Fmailman%2Fmessage%2F36260915%2F&data=02%7C01%7Cramasamy-a%40hcl.com%7C451e8dcbe7b14a7d067b08d76c3216ed%7C189de737c93a4f5a8b686f4ca9941912%7C0%7C0%7C637096834699550969&sdata=igA8%2Bc9X0oFnW8lyJRQIILOqlePIv4OdnlyMUZGrHKQ%3D&reserved=0>
>>
>> https://sourceforge.net/p/podofo/mailman/message/36683139/
>> <https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsourceforge.net%2Fp%2Fpodofo%2Fmailman%2Fmessage%2F36683139%2F&data=02%7C01%7Cramasamy-a%40hcl.com%7C451e8dcbe7b14a7d067b08d76c3216ed%7C189de737c93a4f5a8b686f4ca9941912%7C0%7C0%7C637096834699550969&sdata=UTqo02i%2FFKMf264jZ9aAA%2F1hYIgU35t8aUN1I8MDMqo%3D&reserved=0>
>>
>>
>>
>> From what I googled indicates that seems truetype fonts do not support
>> ligatures but opentype fonts do support them. And seems podofo does not
>> support opentype fonts (also from my experience regarding font subsetting):
>>
>>
>>
>> https://sourceforge.net/p/podofo/mailman/message/21215446/
>> <https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsourceforge.net%2Fp%2Fpodofo%2Fmailman%2Fmessage%2F21215446%2F&data=02%7C01%7Cramasamy-a%40hcl.com%7C451e8dcbe7b14a7d067b08d76c3216ed%7C189de737c93a4f5a8b686f4ca9941912%7C0%7C0%7C637096834700260565&sdata=M2Qmmpq0D3t6Yg7yn%2Fw%2FYTO8uBZO%2BYfTvDt0P6nsN9s%3D&reserved=0>
>>
>>
>>
>>
>>
>>
>>
>> On Mon, Nov 18, 2019 at 8:50 AM Anand Ramasamy <ramasam...@hcl.com>
>> wrote:
>>
>> Dear All,
>>
>>
>>
>> Thanks in advance for the help.
>>
>>
>>
>> We are facing an issue with Arabic characters when using Podofo library
>> to draw it in PDF file.
>>
>>
>>
>> The characters are not joined together in the output pdf file.
>>
>> Below is the code that we have implemented to draw Arabic characters in
>> PDF file.
>>
>>
>>
>> Attached the expected output and actual output snapshots.
>>
>>
>>
>> Kindly let us know whether any other settings needs to be enabled or
>> should we use any other API.
>>
>>
>>
>> ...
>>
>> pFont = document->CreateFont("Arabic Typesetting", false, false, false,
>> PdfEncodingFactory::GlobalIdentityEncodingInstance(),
>> PoDoFo::PdfFontCache::eFontCreationFlags_None);
>>
>> painter.SetFont(pFont);
>>
>> ...
>>
>> wstring ar = L"ابناء الشيخ";
>>
>> std::reverse(ar.begin(), ar.end());
>>
>> PdfString str1( ar.c_str() );
>>
>> PdfString pString = str1.ToUnicode();
>>
>>
>>
>> painter.AddText(pString, pString.GetCharacterLength());
>>
>> ...
>>
>>
>>
>> Below are our observations regarding this issue.
>>
>> 1. Value of “pString” in the below line contains individual characters of
>> the Arabic string “ar”.
>>
>>
>>
>> “PdfString pString = str1.ToUnicode();”
>>
>>
>>
>> 2. When “pString” is passed to “AddText” api, the output string written
>> to PDF document is not joined together.
>>
>> Kindly refer to the attached expected  output and actual output
>> screenshots.
>>
>>
>>
>> Regards,
>>
>> Anand.
>>
>> ::DISCLAIMER::
>> ------------------------------
>>
>> The contents of this e-mail and any attachment(s) are confidential and
>> intended for the named recipient(s) only. E-mail transmission is not
>> guaranteed to be secure or error-free as information could be intercepted,
>> corrupted, lost, destroyed, arrive late or incomplete, or may contain
>> viruses in transmission. The e mail and its contents (with or without
>> referred errors) shall therefore not attach any liability on the originator
>> or HCL or its affiliates. Views or opinions, if any, presented in this
>> email are solely those of the author and may not necessarily reflect the
>> views or opinions of HCL or its affiliates. Any form of reproduction,
>> dissemination, copying, disclosure, modification, distribution and / or
>> publication of this message without the prior written consent of authorized
>> representative of HCL is strictly prohibited. If you have received this
>> email in error please delete it and notify the sender immediately. Before
>> opening any email and/or attachments, please check them for viruses and
>> other defects.
>> ------------------------------
>>
>> _______________________________________________
>> Podofo-users mailing list
>> Podofo-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/podofo-users
>> <https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fpodofo-users&data=02%7C01%7Cramasamy-a%40hcl.com%7C451e8dcbe7b14a7d067b08d76c3216ed%7C189de737c93a4f5a8b686f4ca9941912%7C0%7C0%7C637096834700270562&sdata=xHAvTQrV2lqrhRHYN7GVvRJAHDdYzoulnrjN%2BeP5f44%3D&reserved=0>
>>
>>
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to