0

I am developing some code (in Delphi 6) where I draw a widestring on a canvas. This works fine for the drawing itself.

However I would like to enable customer to have variable pitch. I do this currently by calculating a certain spacing and moving this step for each glyph. Works for most, but some scripts have accent marks that suddenly become separated. Illustration below : Incorrect glyph pitch

The top in illustration is my desired output. The disired is from pasting in MSWord, then adding spaces manually. The bottom in illustration is Word, adding letter spacing to a paragraph style.

Other software has same "simple way" of drawing, I tried InkScape as well.

Question is - can it be done using a Windows API ? Or is it a question of knowing which codepoints represent accent marks, then avoid space after these ? (the list should be this one I guess) The last can of course be done, but is like a little "hack" in my book.

For reference, I use the "DrawTextW" function, similar to example here

My code for output:

for d := 1 to Textlength do
begin
  DrawTextW(
    bmp.Canvas.Handle,
    PWideChar(copy(TextW,d,1)),
    1,
    tmpArea,
    DT_SINGLELINE or DT_NOCLIP);

  // widest is width of widest char, for spacing
  //
  // this is where I could check if next is a nonspacing/combining
  // to avoid adding space.
  if dtoPitch in Options.Option then
    tmpArea.Left := tmpArea.Left + widest;
end;
MyICQ
  • 987
  • 1
  • 9
  • 25
  • 2
    You have to consider that unicode glyphs are arbitrarily multi-byte entities. [Combining characters](https://en.wikipedia.org/wiki/Combining_character) can't simply be rendered alone - it looks like you're treating each two-byte pair as a glyph. With unicode this is not possible. You have to parse the string to determine which bytes belong to the same glyph. – J... Apr 23 '19 at 12:39
  • Without seeing your code we can only guess at what has happened. Please provide a [mcve] – David Heffernan Apr 23 '19 at 12:44
  • @J... I think you come to the same conclusion I did. Simply going over the code by each glyph, adding space, is wrong, since some glyphs combine with the previous. – MyICQ Apr 23 '19 at 12:49
  • 2
    See also [Detecting and Retrieving codepoints and surrogates from a Delphi String](https://stackoverflow.com/q/32020126/576719) – LU RD Apr 23 '19 at 13:02

0 Answers0