Ticket #138: WinWorkstation-widthOf:from:to:inFont:.st

File WinWorkstation-widthOf:from:to:inFont:.st, 1.4 KB (added by jan vrany, 7 years ago)
Line 
1"{ Encoding: utf8 }" !
2!WinWorkstation methodsFor:'font stuff'!
3
4widthOf:aString from:index1 to:index2 inFont:aFontId
5 | w |
6
7 w := self
8 widthOf:aString from:index1 to:index2 inFont:aFontId
9 in:nil with:nil.
10
11 w isNil ifTrue:[
12 "/ The primitive returns nil (sigh) for invalid (non-string) argument
13
14 | s |
15
16 s := aString asString.
17 s isUnicode32String ifTrue:[
18 "/ Special case for Unicode32Strings: copy only relevant portion of the
19 "/ string unto Unicode16String which can be handled by the primitive.
20 "/ This significantly speeds up things when the originak string is
21 "/ very, very big and we need a width of only a very small portion of it.
22 "/
23 "/ See https://swing.fit.cvut.cz/projects/stx-jv/ticket/138
24
25 | len s16 |
26
27 len := index2 - index1 + 1.
28 s16 := Unicode16String new: len.
29 s16 replaceFrom: 1 to: len with: s startingAt: index1.
30 w := self
31 widthOf:s16 from:1 to:len inFont:aFontId
32 in:nil with:nil
33 ] ifFalse:[
34 w := self
35 widthOf:s from:index1 to:index2 inFont:aFontId
36 in:nil with:nil
37 ].
38 ].
39 ^ w
40
41 "Modified (comment): / 10-05-2017 / 19:59:29 / jv"
42! !
43