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.

user5515
  • 301
  • 2
  • 18
  • In order to you get answers, I recommend you open a question for each isolated issue you have, show some code and exactly what you would want in a concise way. Have you tried one of these: https://stackoverflow.com/questions/8113866, https://stackoverflow.com/questions/14535700, https://stackoverflow.com/questions/36801391? – Andre Figueiredo Apr 16 '19 at 13:09
  • I'm only asking for one issue -the first one I mentioned which is also on the title. None of the links in your comment addresses this issue. – user5515 Apr 16 '19 at 13:14
  • I have previously created javascript that drew multi-styled text to canvas using measureText, but most of the time it's better to overlay another html element containing text styled using normal html and css. The canvas element is mostly for things that cannot be easily done with normal html elements and styling text is something normal html elements do very well. – aptriangle Apr 19 '19 at 14:53
  • Yes, but my project depends on canvas as a necessary step for things that cannot be done at all with HTML elements, like 3D and VR which is why I'm using canvas in the first place. Interestingly enough, despite the exponential growth of VR, canvas has been left in cage-era, so everyone has to make all missing features by himself. Imagine the thousands of man-hours wasted... Another impediment in technology growth (of the many). – user5515 Apr 20 '19 at 12:40
  • *cave-man era... – user5515 Apr 21 '19 at 11:21

0 Answers0