Author Topic: True spacing for letters  (Read 6761 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
True spacing for letters
« on: November 08, 2006, 02:35:47 PM »
Does anyone know how to get the true spacing for letters from looking at the font file?  I notice that the .shx files are encrypted; is there any way to read them?  What I have done in the past is divide the length of the text string by the number of characters.  It works okay most of the time, but I'm wanting a better (more accurate) way.

Attached is an example of what I do now.  See how it kind of works for the top one, but the bottom one is way off.

Thanks, and any/all help is appreciated.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

dan19936

  • Guest
Re: True spacing for letters
« Reply #1 on: November 08, 2006, 03:31:49 PM »
I believe SHX files are compiled not encrypted. Google for SHX2SHP for a way to create a shape file for your fonts. Then you'll have to parse the file to get the spacing.

Dan

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: True spacing for letters
« Reply #2 on: November 08, 2006, 03:32:30 PM »
Wow, the shx can be decompiled to a shp file but even then the character width can only be determined by following the shape definition step point by point.
That is quite a task in itself. 
Why not entmake the text, get the BBox, & remove the text?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

LE

  • Guest
Re: True spacing for letters
« Reply #3 on: November 08, 2006, 03:38:03 PM »
In the express routines there is: dumpshx.exe

Explain a little more of what you are intended to do.... my 2 brain cells left do not work at 100% anymore...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: True spacing for letters
« Reply #4 on: November 08, 2006, 03:58:47 PM »
Thanks all, but these ways don't seem able to be put into a working routine that will function as fast as one would want.  Here is my idea for a current problem I had today.

I had a bunch of text lines that didn't line up right.  I need to break the text in place by picking a point.  Example
"Here is one line of text that I might want to make two."
After running the routine and picking a point between "that" and "I", you would have two text entities like
"Here is one line of text that" "I might want to make two."

I have a line-up routine that I would use after to space them correctly.  I can see a use for this in the future, so I wanted to create a routine to do it, but I didn't know how to get the correctly picked point in relation to the text selected.  As the image shows in my first post, when selecting a point, you might not be breaking the text string at the right spot, which is how one of my routines works now, but I was hoping for a better way.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: True spacing for letters
« Reply #5 on: November 08, 2006, 04:16:33 PM »
Thinking out aloud here. 8-)
What if you used grread to detect the text object & then as you move the pointer
you could display using grvecs the two characters where the division would take place.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: True spacing for letters
« Reply #6 on: November 08, 2006, 04:52:14 PM »
You might find some usefum stuff here for creating your lettering.
http://www.theswamp.org/index.php?topic=8916.msg116436#msg116436


PS
More thoughts.
Perhaps you should display the left side text only as an indication of where the break would take place.
« Last Edit: November 08, 2006, 04:54:20 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: True spacing for letters
« Reply #7 on: November 08, 2006, 05:13:37 PM »
Thanks for the ideas Alan.  I will see what I can come up with.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: True spacing for letters
« Reply #8 on: November 08, 2006, 05:41:44 PM »
Thanks all, but these ways don't seem able to be put into a working routine that will function as fast as one would want.  Here is my idea for a current problem I had today.

I had a bunch of text lines that didn't line up right.  I need to break the text in place by picking a point.  Example
"Here is one line of text that I might want to make two."
After running the routine and picking a point between "that" and "I", you would have two text entities like
"Here is one line of text that" "I might want to make two."

I have a line-up routine that I would use after to space them correctly.  I can see a use for this in the future, so I wanted to create a routine to do it, but I didn't know how to get the correctly picked point in relation to the text selected.  As the image shows in my first post, when selecting a point, you might not be breaking the text string at the right spot, which is how one of my routines works now, but I was hoping for a better way.

Tim

I use your BreakText.lsp to break my dtext, and it works perfectly.
Breaks a text object at a point the user picks, and places the rest of the text on the next line below it.
Is this what you are talking about?

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: True spacing for letters
« Reply #9 on: November 08, 2006, 05:46:00 PM »
Tim

I use your BreakText.lsp to break my dtext, and it works perfectly.
Breaks a text object at a point the user picks, and places the rest of the text on the next line below it.
Is this what you are talking about?

Gary

That is the existing routine Gary, glad it works for you.  I still use it also.  I wanted something different.  It will break the text objects, but leave them on the same line, and in the same place.  I can then later position them where I want them.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

hmspe

  • Bull Frog
  • Posts: 362
Re: True spacing for letters
« Reply #10 on: November 08, 2006, 11:25:27 PM »
I have a routine that reforms paragraphs of text that uses the following.  data2 is the base string.  index is the counter for substring length.
I start with index = 1 then loop with (setq index (+ index 1)) until tlen is greater than whatever my desired width is.  No speed complaints.


Code: [Select]
                     (setq tb
                             (textbox (list (cons 1 (substr data2 1 index))))
                      )
                                        ; get the bounding points of the
                                        ; substring
                      (setq
                        tlen (abs (- (car (car tb)) (car (cadr tb))))
                      )
                                        ; get the width [in X]

Martin
"Science is the belief in the ignorance of experts." - Richard Feynman

T.Willey

  • Needs a day job
  • Posts: 5251
Re: True spacing for letters
« Reply #11 on: November 09, 2006, 12:08:28 PM »
Thanks Martin, but I don't think that will work for what I'm wanting.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

hmspe

  • Bull Frog
  • Posts: 362
Re: True spacing for letters
« Reply #12 on: November 10, 2006, 12:38:59 AM »
Thanks Martin, but I don't think that will work for what I'm wanting.

I must be missing something.  What I think you're wanting is to be able to click within a selected text string and be able to determine what's to the left and what's to the right.  I don't see why textbox won't work.  You have a group 10 dxf code for the text, so you know the start point, and you have the X value for the click, so getting a length to compare the delta X from textbox to is trivial.   
 
Maybe I should post the whole routine I use.  I use it to reformat notes and such.  You select the text entities, then click where the new right edge of the text should be.  It works with any left justification or center justification.  Handles gaps between lines.  There is a known problem the first time it runs in a session with the new line width.  Probably missed initializing a variable, which some day I'll have time to track down.  I just run the routine asecond time at this point.  Probably a lot that could be done to optimize the code.  Uses bits of code and ideas picked up many places, including the swamp.
 
The routine if relatively fast.  Reformatting 170 lines of my plan spec on my laptop is around 3 seconds.  On my desptop computer a lot faster than that.  For one or two lines it's as fast as the screen can paint, even on the laptop.

This may not be exactly what you're trying to do, but from your description it may be close.  If not, no problem.

Martin   
"Science is the belief in the ignorance of experts." - Richard Feynman

Didge

  • Bull Frog
  • Posts: 211
Re: True spacing for letters
« Reply #13 on: November 10, 2006, 04:46:40 AM »
Just a lazy thought from a lazy coder;

1. Entsel  text string at desired break point.
2. Calculate desired width (ie distance between leftmost text box coordinate + entsel point)
3. Recreate string using MTEXT using the width value as calculated above.
4. Explode stacked Mtext back to regular text.


« Last Edit: November 10, 2006, 04:47:49 AM by Didge »
Think Slow......

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: True spacing for letters
« Reply #14 on: November 10, 2006, 07:52:21 AM »
Perhaps this is  a poor example but it's all I could come up with at the moment.
I'm still waiting on the coffee maker to finish! :doa:
You see the character width does not work when dealing with narrow characters
like 'I' and '1"  as they throw the width calculation off.

Hope I'm on the right track here.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.