Trouble getting text width

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble getting text width

Carl Gundel-2
I am having trouble laying out text.  I render each word individually and handle bold, italic, wordwrapping etc.  When I use the CgFont>>textWidth: method it doesn't seem to give me a big enough number.  Some of the words will run into each other.  The effect is reproducible.  I can use different printers and fonts but it doesn't really make much difference.
 
textWidth: string
 "Answer the width in pixels of the given string
  using the receiver as its font."
 | osString hdc oldHfont size |
 "If the size of the string is zero, return a size of zero."
 string size == 0 ifTrue: [^0].
 PlatformString == String
  ifTrue: [ osString := string asSBString ]
  ifFalse: [ osString := PlatformString fromString: (serverResource validateLeadBytes: string) ].
 server beginRequest.
 hdc := server deviceContext.
 oldHfont := hdc selectObject: serverResource handle.
 hdc
  getTextExtentPoint: osString
  cbString: osString size
  lpSize: (size := OSSize new).
 hdc selectObject: oldHfont.
 server endRequest.
 ^size cx
 
Any ideas?
 
Thanks,
 
-Carl

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble getting text width

Instantiations mailing list
Hi Carl,

I think getTextExtentPoint does not really take intercharacter spacing or justification into account.
You might want to try to print using winapi call ExtTextOut.

Did you already try to use winApi call DrawText  instead?
I saw that this method is even used in OSWidget textExtent:

I know that problem and I know that there is a solution on that, but I do now more have aceess to my former implementation. Sorry.

Sebastian


Am 27.05.2015 um 14:02 schrieb Carl Gundel:
I am having trouble laying out text.  I render each word individually and handle bold, italic, wordwrapping etc.  When I use the CgFont>>textWidth: method it doesn't seem to give me a big enough number.  Some of the words will run into each other.  The effect is reproducible.  I can use different printers and fonts but it doesn't really make much difference.
 
textWidth: string
 "Answer the width in pixels of the given string
  using the receiver as its font."
 | osString hdc oldHfont size |
 "If the size of the string is zero, return a size of zero."
 string size == 0 ifTrue: [^0].
 PlatformString == String
  ifTrue: [ osString := string asSBString ]
  ifFalse: [ osString := PlatformString fromString: (serverResource validateLeadBytes: string) ].
 server beginRequest.
 hdc := server deviceContext.
 oldHfont := hdc selectObject: serverResource handle.
 hdc
  getTextExtentPoint: osString
  cbString: osString size
  lpSize: (size := OSSize new).
 hdc selectObject: oldHfont.
 server endRequest.
 ^size cx
 
Any ideas?
 
Thanks,
 
-Carl
--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble getting text width

Carl Gundel-2
Thanks Sebastian.  I expect it to work correctly because I am porting this from VSE.  In either case (VSE or VA) the GetTextExtentPointA api is called.  It works in our VSE app.  Strange.
 
-Carl

On Wednesday, May 27, 2015 at 5:23:18 PM UTC-4, Sebastian Heidbrink wrote:
Hi Carl,

I think getTextExtentPoint does not really take intercharacter spacing or justification into account.
You might want to try to print using winapi call ExtTextOut.

Did you already try to use winApi call DrawText  instead?
I saw that this method is even used in OSWidget textExtent:

I know that problem and I know that there is a solution on that, but I do now more have aceess to my former implementation. Sorry.

Sebastian


Am 27.05.2015 um 14:02 schrieb Carl Gundel:
I am having trouble laying out text.  I render each word individually and handle bold, italic, wordwrapping etc.  When I use the CgFont>>textWidth: method it doesn't seem to give me a big enough number.  Some of the words will run into each other.  The effect is reproducible.  I can use different printers and fonts but it doesn't really make much difference.
 
textWidth: string
 "Answer the width in pixels of the given string
  using the receiver as its font."
 | osString hdc oldHfont size |
 "If the size of the string is zero, return a size of zero."
 string size == 0 ifTrue: [^0].
 PlatformString == String
  ifTrue: [ osString := string asSBString ]
  ifFalse: [ osString := PlatformString fromString: (serverResource validateLeadBytes: string) ].
 server beginRequest.
 hdc := server deviceContext.
 oldHfont := hdc selectObject: serverResource handle.
 hdc
  getTextExtentPoint: osString
  cbString: osString size
  lpSize: (size := OSSize new).
 hdc selectObject: oldHfont.
 server endRequest.
 ^size cx
 
Any ideas?
 
Thanks,
 
-Carl
--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="f07QHUMaYNwJ">va-smalltalk...@googlegroups.com.
To post to this group, send email to <a onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="f07QHUMaYNwJ">va-sma...@....
Visit this group at <a onmousedown="this.href='http://groups.google.com/group/va-smalltalk';return true;" onclick="this.href='http://groups.google.com/group/va-smalltalk';return true;" href="http://groups.google.com/group/va-smalltalk" rel="nofollow" target="_blank">http://groups.google.com/group/va-smalltalk.
For more options, visit <a onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;" href="https://groups.google.com/d/optout" rel="nofollow" target="_blank">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble getting text width

Carl Gundel-2
In reply to this post by Instantiations mailing list
Okay, I've had a look at the DrawText method.  That might work but the code I'm porting doesn't lay out while it is rendering.  It computes all this in advance and then prints later, so using a drawing routine to compute spacing isn't a good fit.  Perhaps I can make it work.  Still at a loss why the textWidth: method works for this in our VSE app, but doesn't in the VAST version.  I will dig harder on this first before I abandon it.
 
Thanks again!
 
-Carl

On Wednesday, May 27, 2015 at 5:23:18 PM UTC-4, Sebastian Heidbrink wrote:
Hi Carl,

I think getTextExtentPoint does not really take intercharacter spacing or justification into account.
You might want to try to print using winapi call ExtTextOut.

Did you already try to use winApi call DrawText  instead?
I saw that this method is even used in OSWidget textExtent:

I know that problem and I know that there is a solution on that, but I do now more have aceess to my former implementation. Sorry.

Sebastian


Am 27.05.2015 um 14:02 schrieb Carl Gundel:
I am having trouble laying out text.  I render each word individually and handle bold, italic, wordwrapping etc.  When I use the CgFont>>textWidth: method it doesn't seem to give me a big enough number.  Some of the words will run into each other.  The effect is reproducible.  I can use different printers and fonts but it doesn't really make much difference.
 
textWidth: string
 "Answer the width in pixels of the given string
  using the receiver as its font."
 | osString hdc oldHfont size |
 "If the size of the string is zero, return a size of zero."
 string size == 0 ifTrue: [^0].
 PlatformString == String
  ifTrue: [ osString := string asSBString ]
  ifFalse: [ osString := PlatformString fromString: (serverResource validateLeadBytes: string) ].
 server beginRequest.
 hdc := server deviceContext.
 oldHfont := hdc selectObject: serverResource handle.
 hdc
  getTextExtentPoint: osString
  cbString: osString size
  lpSize: (size := OSSize new).
 hdc selectObject: oldHfont.
 server endRequest.
 ^size cx
 
Any ideas?
 
Thanks,
 
-Carl
--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="f07QHUMaYNwJ">va-smalltalk...@googlegroups.com.
To post to this group, send email to <a onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="f07QHUMaYNwJ">va-sma...@....
Visit this group at <a onmousedown="this.href='http://groups.google.com/group/va-smalltalk';return true;" onclick="this.href='http://groups.google.com/group/va-smalltalk';return true;" href="http://groups.google.com/group/va-smalltalk" rel="nofollow" target="_blank">http://groups.google.com/group/va-smalltalk.
For more options, visit <a onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;" href="https://groups.google.com/d/optout" rel="nofollow" target="_blank">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble getting text width

Instantiations mailing list
Hi Carl,

according to MSDN there is a slight change that you might get more accurate results using "getTextExtentPoint32: arg1 arg3: arg2 arg4: arg3 "
Did you give that a try already?

Sebastian



Am 28.05.2015 um 08:11 schrieb Carl Gundel:
Okay, I've had a look at the DrawText method.  That might work but the code I'm porting doesn't lay out while it is rendering.  It computes all this in advance and then prints later, so using a drawing routine to compute spacing isn't a good fit.  Perhaps I can make it work.  Still at a loss why the textWidth: method works for this in our VSE app, but doesn't in the VAST version.  I will dig harder on this first before I abandon it.
 
Thanks again!
 
-Carl

On Wednesday, May 27, 2015 at 5:23:18 PM UTC-4, Sebastian Heidbrink wrote:
Hi Carl,

I think getTextExtentPoint does not really take intercharacter spacing or justification into account.
You might want to try to print using winapi call ExtTextOut.

Did you already try to use winApi call DrawText  instead?
I saw that this method is even used in OSWidget textExtent:

I know that problem and I know that there is a solution on that, but I do now more have aceess to my former implementation. Sorry.

Sebastian


Am 27.05.2015 um 14:02 schrieb Carl Gundel:
I am having trouble laying out text.  I render each word individually and handle bold, italic, wordwrapping etc.  When I use the CgFont>>textWidth: method it doesn't seem to give me a big enough number.  Some of the words will run into each other.  The effect is reproducible.  I can use different printers and fonts but it doesn't really make much difference.
 
textWidth: string
 "Answer the width in pixels of the given string
  using the receiver as its font."
 | osString hdc oldHfont size |
 "If the size of the string is zero, return a size of zero."
 string size == 0 ifTrue: [^0].
 PlatformString == String
  ifTrue: [ osString := string asSBString ]
  ifFalse: [ osString := PlatformString fromString: (serverResource validateLeadBytes: string) ].
 server beginRequest.
 hdc := server deviceContext.
 oldHfont := hdc selectObject: serverResource handle.
 hdc
  getTextExtentPoint: osString
  cbString: osString size
  lpSize: (size := OSSize new).
 hdc selectObject: oldHfont.
 server endRequest.
 ^size cx
 
Any ideas?
 
Thanks,
 
-Carl
--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a moz-do-not-send="true" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="f07QHUMaYNwJ">va-smalltalk...@googlegroups.com.
To post to this group, send email to <a moz-do-not-send="true" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="f07QHUMaYNwJ">va-sma...@....
Visit this group at <a moz-do-not-send="true" onmousedown="this.href='http://groups.google.com/group/va-smalltalk';return true;" onclick="this.href='http://groups.google.com/group/va-smalltalk';return true;" href="http://groups.google.com/group/va-smalltalk" rel="nofollow" target="_blank">http://groups.google.com/group/va-smalltalk.
For more options, visit <a moz-do-not-send="true" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;" href="https://groups.google.com/d/optout" rel="nofollow" target="_blank">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble getting text width

Carl Gundel-2

I'll have a look at that.  Thanks.  :-)
 
On Thursday, May 28, 2015 at 11:20:49 AM UTC-4, Sebastian Heidbrink wrote:
Hi Carl,

according to MSDN there is a slight change that you might get more accurate results using "getTextExtentPoint32: arg1 arg3: arg2 arg4: arg3 "
Did you give that a try already?

Sebastian



Am 28.05.2015 um 08:11 schrieb Carl Gundel:
Okay, I've had a look at the DrawText method.  That might work but the code I'm porting doesn't lay out while it is rendering.  It computes all this in advance and then prints later, so using a drawing routine to compute spacing isn't a good fit.  Perhaps I can make it work.  Still at a loss why the textWidth: method works for this in our VSE app, but doesn't in the VAST version.  I will dig harder on this first before I abandon it.
 
Thanks again!
 
-Carl

On Wednesday, May 27, 2015 at 5:23:18 PM UTC-4, Sebastian Heidbrink wrote:
Hi Carl,

I think getTextExtentPoint does not really take intercharacter spacing or justification into account.
You might want to try to print using winapi call ExtTextOut.

Did you already try to use winApi call DrawText  instead?
I saw that this method is even used in OSWidget textExtent:

I know that problem and I know that there is a solution on that, but I do now more have aceess to my former implementation. Sorry.

Sebastian


Am 27.05.2015 um 14:02 schrieb Carl Gundel:
I am having trouble laying out text.  I render each word individually and handle bold, italic, wordwrapping etc.  When I use the CgFont>>textWidth: method it doesn't seem to give me a big enough number.  Some of the words will run into each other.  The effect is reproducible.  I can use different printers and fonts but it doesn't really make much difference.
 
textWidth: string
 "Answer the width in pixels of the given string
  using the receiver as its font."
 | osString hdc oldHfont size |
 "If the size of the string is zero, return a size of zero."
 string size == 0 ifTrue: [^0].
 PlatformString == String
  ifTrue: [ osString := string asSBString ]
  ifFalse: [ osString := PlatformString fromString: (serverResource validateLeadBytes: string) ].
 server beginRequest.
 hdc := server deviceContext.
 oldHfont := hdc selectObject: serverResource handle.
 hdc
  getTextExtentPoint: osString
  cbString: osString size
  lpSize: (size := OSSize new).
 hdc selectObject: oldHfont.
 server endRequest.
 ^size cx
 
Any ideas?
 
Thanks,
 
-Carl
--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to va-smalltalk...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at <a onmousedown="this.href='http://groups.google.com/group/va-smalltalk';return true;" onclick="this.href='http://groups.google.com/group/va-smalltalk';return true;" href="http://groups.google.com/group/va-smalltalk" rel="nofollow" target="_blank">http://groups.google.com/group/va-smalltalk.
For more options, visit <a onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;" href="https://groups.google.com/d/optout" rel="nofollow" target="_blank">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="KXD6zLvj7QsJ">va-smalltalk...@googlegroups.com.
To post to this group, send email to <a onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="KXD6zLvj7QsJ">va-sma...@....
Visit this group at <a onmousedown="this.href='http://groups.google.com/group/va-smalltalk';return true;" onclick="this.href='http://groups.google.com/group/va-smalltalk';return true;" href="http://groups.google.com/group/va-smalltalk" rel="nofollow" target="_blank">http://groups.google.com/group/va-smalltalk.
For more options, visit <a onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;" href="https://groups.google.com/d/optout" rel="nofollow" target="_blank">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.