1

I've been playing around with the idea of building a web based design application with advanced typesetting.

The HTML canvas unfortunately does not have much power in text rendering and seems to be the major obstacle for this.

Freetype has python bindings and there seems to be an implementation via node js, but the question I have is this:

Even if freetype is accessible via node...would it allow realtime typesetting or will it always feed the end user a static rendered image/result on the page/canvas?

In other words...is it technically conceivable to have a frontend with draggable/droppable and editable text boxes with type rendered via freetype and not the browser?

venergiac
  • 7,469
  • 2
  • 48
  • 70

1 Answers1

0

You're not the only one playing around with that idea... :-)

Currently it would be difficult, not so much due to the rendering capability but more due to the lack of full implementation of the TextMetric object 1).

The standard specify the object like this:

interface TextMetrics {
  // x-direction
  readonly attribute double width; // advance width -- only one implemented (!)*
  readonly attribute double actualBoundingBoxLeft;
  readonly attribute double actualBoundingBoxRight;

  // y-direction
  readonly attribute double fontBoundingBoxAscent;
  readonly attribute double fontBoundingBoxDescent;
  readonly attribute double actualBoundingBoxAscent;
  readonly attribute double actualBoundingBoxDescent;
  readonly attribute double emHeightAscent;
  readonly attribute double emHeightDescent;
  readonly attribute double hangingBaseline;
  readonly attribute double alphabeticBaseline;
  readonly attribute double ideographicBaseline;
};

* At current time of writing.

You would need most of these properties to be able to do advanced typesetting (as well as bearings).

There are ways to get around this by using a selection of typefaces/fonts and use other platforms to run through the typefaces and store the typeface's characteristics such as those above as meta-data in em units.

The rendering capability and performance can be solved in more than one way by smart (image) caching and clever setup of the font you intend to use - all on client side - and is not really an issue IMO (but topic is too broad to cover here). Remember that the look on the screen would be a preview (at an 72/96 arbitrary DPI/PPI versus the typical 300 DPI for prints).

Even if freetype is accessible via node...would it allow realtime typesetting or will it always feed the end user a static rendered image/result on the page/canvas?

This approach would only introduce another delay in context of real-time use (server render + bitmap transfer to client) which is probably slower than rendering the internal paths of the glyphs using canvas directly.

You can perhaps use it to render cached glyphs (for consistency on all browser platforms but not for real-time rendering) provided it also gives you the glyph metric data, or you would have a hard time to be able to place your glyphs correctly and accurately on the screen.

And also as a side note: don't forget that you would also have to have a target file format (which means you also need to write a parser for such format) to store your document structure in (ie. ODF, PDF or some other well known and supported format).

As a tip: Take a look at the PDF.js project which Mozilla Firefox uses as an internal PDF parser and viewer which can show one way of organizing and structuring all these objects for rendering to screen (I would not recommend a pseudo-text format as PDF for internal handling but check it out for the sake of structuring a type-setting document).

1) We can only speculate (I know I have) why the TextMetric is not yet available as the data is already available internally from the text render engine and it should be a simple matter of mapping those numbers to the TextMetric object associated with the current typeface.

If it has strategic reason and that "some" wants to be ahead when it's first released with an online more advance "WORD/DOC/WRITE"; I don't know, but lets hope the data will be available in close future. In the mean time a LUT (look-up-table) with meta-data for predefined fonts could be one way to go for the metric part.

  • Totally off-topic...but thanks for the memories! :) In the 1980's I helped someone run a typesetting machine using a KayPro computer. – markE Feb 01 '14 at 21:39
  • Thanks Ken - good answer! I'm a mag designer and switched from Adobe suite to Scribus - great, but the use of qt etc made me think that an html web app could be great. The tools seem to be there to allow for everything except for the typesetting. I worked on a project once that rendered 300dpi print material from the canvas - worked great. Freetype, would be perfect for this, but one would need to use it client side. there is a js port, but the link to the file is gone so I don't know what the state of that project is. Stubbornly haven't given up though. Will still toy with this. ;-) – user3261239 Feb 02 '14 at 07:10
  • @user3261239 I found something that you may can use (I didn't dig deep into it though): https://github.com/luismreis/node-openvg-freetype Yeah, typesetting is a weak point (Chrome is also dumping Adobe's region-flow support so obviously this is not a focus area). Should work fine with 300 DPI on canvas and if you can get freetype to work with this let us know! :) Need to check out Scribus - been an Adobe customer since before CS but said stop at CS5.. –  Feb 02 '14 at 08:03
  • 1
    @markE hehe, yeah I didn't do much typesetting in the 80's but I can remember I accidentally experimented with OCR, bitmap fonts and neural networks but as you know computers wasn't so efficient back then so the minutes each test took kind of killed off the enthusiasm (but reemerged later in the OMR and barcode area instead). I did make some in-house typesetting/catalog software for a company some years later specialized to set tables for ILO/3.1B lifting certifications. Hardly an all-round thing though.. :-P –  Feb 02 '14 at 08:57
  • Hey Ken. I also found that project a few days ago and then started investigating node, which, up to that point, I was unaware of - quite an exciting project. I am going to experiment with this a bit. As for Scribus/Gimp - great projects. I miss certain parts of InDesign, but Scribus gets the job done, but I want a new complete solution and web apps seem to be the future for this. I'm also a competent web developer and very poor at C++. I can't see any real obstacle apart from this KEY aspect. – user3261239 Feb 02 '14 at 08:59
  • @user3261239 I just remember that I gave an answer in this thread: http://stackoverflow.com/questions/17359711/how-do-i-get-glyph-outlines-of-a-letter-as-bezier-paths-using-javascript/17360562#17360562 If you see OP's own answer you can see he made a font parser to extract their outlines for use on canvas. It's probably worth taking a look at this library as you should be able to get the needed metrics and you will also get the needed paths. –  Feb 02 '14 at 09:08
  • That looks very interesting...will definitely investigate further. Just seems an unfortunate round-about way to do it...but will have to have a deeper look. Compiling openvg-fteetype now - see what that allows. Will keep you posted if anything interesting happens. :-) – user3261239 Feb 02 '14 at 09:21