Html2canvas: Arabic font rendering

Created on 22 Sep 2016  路  6Comments  路  Source: niklasvh/html2canvas

Hey guys, I've seen this issue opened before, however I can't get it to work properly for a custom Arabic font.

Here is how the HTML looks: http://prntscr.com/ckxcp3

And how the html2canvas 0.5.0-alpha1 looks: http://prnt.sc/ckxd1v

As you can see, the characters are all tangled up. Any ideas?

Update:
On line 2321 I replaced !hasUnicode with hasUnicode, which works almost perfect:
http://prnt.sc/ckxnjo
Now the font looks perfect, but normal characters "!" and "(" have wrong direction.

Update2:
Managed to find a fix based on n-a-g-r-o-m' solution [https://github.com/niklasvh/html2canvas/issues/686]

Unicode

Most helpful comment

For version 0.5.0-beta3

Change:
var textList = (!this.options.letterRendering || noLetterSpacing(container)) && !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character)

To:
var textList = (!this.options.letterRendering || noLetterSpacing(container)) || !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character)

Change the && to ||

And it works perfect for Arabic without any CSS modifications

Worked for me along with letter-spacing: normal

All 6 comments

For version 0.5.0-beta3

Change:
var textList = (!this.options.letterRendering || noLetterSpacing(container)) && !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character)

To:
var textList = (!this.options.letterRendering || noLetterSpacing(container)) || !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character)

Change the && to ||

And it works perfect for Arabic without any CSS modifications

I recently tried to draw arabic/persian html to canvas and it rendered correctly
can someone else verify that it is solved?

sounds like the problem is fixed,
just beware of word-wrap : break-word style too, it still splits the Arabic/Persian words into separate characters.

For version 0.5.0-beta3

Change:
var textList = (!this.options.letterRendering || noLetterSpacing(container)) && !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character)

To:
var textList = (!this.options.letterRendering || noLetterSpacing(container)) || !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character)

Change the && to ||

And it works perfect for Arabic without any CSS modifications

Worked for me along with letter-spacing: normal

don't use word-break: break-word;

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tibewww picture tibewww  路  4Comments

stevencherry1 picture stevencherry1  路  3Comments

koreanman picture koreanman  路  4Comments

ABHIKSINGHH picture ABHIKSINGHH  路  3Comments

wbarrantes picture wbarrantes  路  3Comments