No announcement yet.

Character Spacing (Not Kerning)

  • Filter
  • Time
  • Show
Clear All
new posts

  • Character Spacing (Not Kerning)

    MS Office appears to have a setting for increasing letter-to-letter spacing, called character spacing or character tracking. I'd like to know how to do that in a PowerBASIC app, such as when text is displayed in a RichEdit control.

    If I were drawing on a Graphic control, I could manage spacing (and wordwrapping) myself.

    I've looked around the web and the only potential solution I've found is to use a Font Editor to modify letter spacing. If that would work, I'd have to install the custom font for use in my apps, but at least the desired result would be available.

  • #2
    Is this just for display? or will you allow editing in the box?

    If display-only you "could" just insert a space after each character and that will give the additional inter-spacing you might be looking for... or would that be to much space?

    now is the time for all good men to come to the aid of their country.

    n o w   i s   t h e   t i m e   f o r   a l l   g o o d   m e n   t o   c o m e   t o   t h e   a i d   o f   t h e i r   c o u n t r y .
    <b>George W. Bleck</b>
    <img src=''>


    • #3
      Hi George!
      I would allow editing..

      The problem with spaces is that an edit control won't wrap correctly.


      • #4
        Let's try something quick,
        if from NotePad, meaning not WordPad, you save the text below as a .rtf file and then you reopen it with WordPad.
        Does it look like what you want?

        Magic word seems to be "expndtw", expndtw360 = 18 points.
        {\rtf1\ansi\ansicpg1252\deff0\deflang3084{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\fnil\fcharset0 Calibri;}}
        {\*\generator Msftedit;}\viewkind4\uc1\pard\sa200\lang1033\expndtw360\f0\fs22 Gary\par


        • #5
          From the RTF specification: (10 years old but still the current spec)
          \expndN Expansion or compression of the space between characters in quarter-points; a negative value compresses (default is 0).
          \expndtwN Expansion or compression of the space between characters in twips; a negative value compresses. For backward compatibility, both \expndtwN and \expndN should be emitted.


          • #6
            Thanks, guys, that is very interesting! How would that translate into displaying extra spacing while a user edits the content? The technique sounds like something I would use by first saving a file, then editing the RTF content, and then reloading it. But not while editing takes place?

            How did you run across the information? I didn't see a hint of it while I was out searching the web.


            • #7
              How did you run across the information?

              Well, in your post, you told me how to, kind of... :-)
              I used Word, selected some text, then used the "Font" menu, "Advanced", "Spacing" "Extended"setted 15 pts.
              Closed the menu, Copy and paste the text from Word to WordPad. Saved it as .rtf and reopened it with NotePad.
              Look at what might be the answer. Et voilà!

              If it's what you want, from there, we know it's possible.
              So, the next search will be on how to do it...


              • #8

                Thanks for the lead!

                I went into word and saw the letter spacing option. That is exactly what I would like to do in a PowerBASIC app! I'll try some additional search terms to try and find something linked to the option.


                • #9
                  I found a GDI API that at least least talks about the possibility.

                  GDI SetTextCharacterExtra

                  I created a RichEdit control, got it's DC and used SetTextCharacterExtra(hDC,15) but it did not seem to have any effect.

                  ... added ... this forum thread discusses SetTextCharacterExtra indicating it only applies when writing text using GDI API.


                  • #10
                    Quick test using the API SetTextharacterExtra


                    • #11
                      Gary Beene I can't speak from experience but you could try using unicode-160 (non-breaking space) as the inter-character space in lieu of ascii 32, although it sounds like you have a real path to follow.
                      <b>George W. Bleck</b>
                      <img src=''>


                      • #13
                        No fair using my own code against me! But yes, I can make it work on a Graphic control but that's a lousy editor for users to use!

                        Well, nothing that actually seems to cross the finish line. But I'm still looking.


                        • #14
                          I did not see any specific message to set the horizontal character spacing.

                          I'm almost sure that the way to do it is to use a EM_STREAMIN / EditStreamCallback to insert rtf code in the rich edit control.
                          The code to insert could look like "\expndtw300\expnd60", note that Bill recommand to use both "expnd" version for more compatibility.

                          A Google search with "Insert rtf code in rich edit control" may give good results...
                          Last edited by Pierre Bellisle; 8 Dec 2018, 12:19 PM.


                          • #15
                            Hi George! The inserted alternate character is certainly something to try out - for viewing at least. Although, I suppose I could subclass the control and make sure that all characters are followed by an invisible character, such as you suggest. I'm not really finding a solution elsewhere so I may have to try out what you suggest

                            And, Howdy, Pierre! Yes, bummer that. I've had discussions with folks who have vision problems and several have told me that the letters of normal fonts are simply too close together for reading. So the need is real and I'll continue to look some more. I tried out a free font editor, but couldn't figure out how to modify a font (such as Arial) to create a new font with the extra character spacing. Surely that's possible. I'll try again tomorrow. Using a font editor is like entering a new universe, with all of the new terminology that seems to be involved. I was hoping that using a font editor would be a simpler task, but I guess I'll have to spend more time with it than expected.


                            • #16
                              Withdrawn - I mixed up horizontal spacing and vertical spacing..


                              • #17
                                Yep, EM_STREAMIN / EditStreamCallback is the way to go.
                                I got something almost working using Börje "". (Hi Börje, good code never die!)

                                I send "{\rtf1 \expndtw60 \expnd12 Test string \expndtw0 \expnd0}" via EM_STREAMIN, SF_RTF
                                and I got horizontal characters spacing... with some bug to be corrected.

                                The nice thing about this is that it open so many possibility, \expndtw being just one of them,
                                see or download Word 2007: Rich Text Format (RTF) Specification, version 1.9.1
                                Last edited by Pierre Bellisle; 8 Dec 2018, 12:21 PM.


                                • #18
                                  I can't wait to see the example. Are you saying a user could edit with extra spacing in place? Or just extra spacing for viewing only?

                                  Maybe I'll go have some popcorn to help calm my nerves!


                                  • #19
                                    Yep. editing is no problem, the whole text or a single character may have custom horizontal spacing, like in MS-Word.
                                    Like Börje was near to say, vertical spacing can also be done via EM_SETPARAFORMAT / PFM_LINESPACING.
                                    I do not have much time to spend on this for now, so, it may take a while before I find a clean way to do it and produce an example.


                                    • #20
                                      I guess my bowl of popcorn needs to be quite large!