1

Some aspects of HTML5 and especially Canvas seem to have remain in the pre-word-processor software era, in the 60's when only typewriters existed.

(This issue) For one, you can't make a word or a sentence bold, or underline it inside a text on the same pass, simply and efficiently. Filltext just fills canvas with a single piece of text and a single style and that's it.

(BTW, a second one is the lack of text-justifying function on both sides for canvas, so I had to made such a function myself using JavaScript. A third, is a bug that prevents changing multiple custom fonts on subsequent canvas operations unless you have pre-use them(!) after initiation (I discovered that workaround after a lot of struggle).

So I'm thinking of two workarounds:

  1. Locate the set of words you want to change the style, calculate the start x,y position and the total length using 'measureText', do the first pass replacing them with spaces, then do a second pass and only write those words with a different style inside the empty space.

  2. Embed 2 or more styles on the same custom font and same language, like they were different languages in Unicode.

Is there another workaround?

I'm asking in case I'm missing something, or someone out there has a decent idea.

4

0 回答 0