--- a/Cairo__ScaledFont.st Tue Feb 16 07:46:52 2016 +0000
+++ b/Cairo__ScaledFont.st Wed Feb 17 06:43:31 2016 +0000
@@ -2,100 +2,96 @@
"{ NameSpace: Cairo }"
-FontDescription subclass:#ScaledFont
- instanceVariableNames:'handle device extents'
- classVariableNames:'Lobby RecentlyUsedFonts'
+CObject subclass:#ScaledFont
+ instanceVariableNames:''
+ classVariableNames:''
poolDictionaries:''
category:'Cairo-Objects'
!
-!ScaledFont class methodsFor:'initialization'!
+!ScaledFont class methodsFor:'instance creation'!
+
+fromFontDescription: aFontDescription
+ ^ self fromFontFace: (FontFace fromFontDescription: aFontDescription) scale: (Screen current verticalPixelPerInch / 72) * aFontDescription size.
-initialize
- "Invoked at system start or when the class is dynamically loaded."
+ "
+ Cairo::ScaledFont fromFontDescription: CodeView defaultFont
+ "
+
+ "Created: / 17-02-2016 / 20:21:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 18-02-2016 / 08:16:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+fromFontFace: face matrix: fontMatrix transformation: transformationMatrix options: options
+ ^ CPrimitives cairo_scaled_font_create: face _: fontMatrix _: transformationMatrix _: options
- "/ please change as required (and remove this comment)
+ "Created: / 17-02-2016 / 20:30:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
- Lobby := Registry new
+fromFontFace: face scale: scale
+ | options font |
+ options := FontOptions new.
+ font := self fromFontFace: face matrix: (Matrix scale: scale) transformation: Matrix identity options: options.
+ options release.
+ ^ font.
+ "
+ Cairo::ScaledFont fromFontDescription: CodeView defaultFont
+ "
- "Modified: / 09-01-2015 / 11:22:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 18-02-2016 / 08:15:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 18-02-2016 / 10:17:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!ScaledFont class methodsFor:'accessing'!
-dllPath
-
- OperatingSystem isMSWINDOWSlike ifTrue:[
- ^ #( 'C:\Windows' 'C:\Windows\System32' "Wild guess, should not harm" )
- ].
-
- OperatingSystem isUNIXlike ifTrue:[
- OperatingSystem getSystemType == #linux ifTrue:[
- | path |
-
- path := #( '/lib' '/usr/lib' '/usr/local/lib' ).
- (OperatingSystem getSystemInfo at:#machine) = 'x86_64' ifTrue:[
- "If the machine is 64bit, prepend standard path for 32bit libs.
- Leave standard paths at the end, as the system might be completely
- 32bit but running on 64bit-capable CPU.
-
- CAVEAT: This is bit dangerous, as on 64bit OS, if ia32 libs are
- not installed byt 64bit sqlite libs are, then 64bit libs are found
- and when a function is called, segfault will occur!!
-
- Q: Is there a way how to figure out if the OS itself is 32bit,
- regardles on CPU?"
- path := #( '/lib32' '/usr/lib32' '/usr/local/lib32' ) , path.
- ].
- ^path
-
- ].
- ].
-
- self error:'Unsupported operating system'
-
- "
- SqliteLibrary dllPath
- "
-
- "Created: / 31-08-2011 / 18:02:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-libraryName
-
- OperatingSystem isUNIXlike ifTrue:[^'libcairo.so.2'].
-
- OperatingSystem isMSWINDOWSlike ifTrue:[^'cairo.dll'].
-
- self error:'Library name for host OS is not known'
-!
-
sizeof
"Returns size of undelaying structure in bytes"
^0
! !
-!ScaledFont methodsFor:'finalization'!
+!ScaledFont methodsFor:'accessing'!
+
+fontMatrix
+ | matrix |
-finalization
- self destroy
+ matrix := Matrix new.
+ CPrimitives cairo_scaled_font_get_font_matrix: self _: matrix.
+ ^ matrix
- "Created: / 09-01-2015 / 10:20:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 18-02-2016 / 10:05:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-finalizationLobby
- "answer a Registry used for finalization.
- Use a generic Registry for any object.
- Subclasses using their own Registry should redefine this"
+referenceCount
+ "Return value or reference counter"
- ^ Lobby
+ ^ CPrimitives cairo_scaled_font_get_reference_count: self.
- "Created: / 09-01-2015 / 10:20:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-02-2016 / 20:16:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
-!ScaledFont methodsFor:'initialize'!
+!ScaledFont methodsFor:'cairo api'!
+
+extents
+ | extents |
+ extents := FontExtents new.
+ Cairo::CPrimitives cairo_scaled_font_extents: self _: extents.
+ ^ extents
+
+ "Created: / 16-02-2016 / 14:56:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+textExtents: aString
+ | extents |
+ extents := TextExtents new.
+ Cairo::CPrimitives cairo_scaled_font_text_extents: self _: aString utf8Encoded _: extents.
+ ^ extents
+
+ "Created: / 16-02-2016 / 14:56:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ScaledFont methodsFor:'private'!
destroy
"Tell Cairo library to destroy the corresponding C object.
@@ -103,111 +99,11 @@
refcounter goes to zero. However, after calling destroy,
this instance should be treated as invalid."
- handle notNil ifTrue:[
- CPrimitives cairo_scaled_font_destroy: handle
- ].
+ CPrimitives cairo_scaled_font_destroy: self.
+ self setAddress: nil.
"Created: / 28-12-2014 / 22:10:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 09-01-2015 / 11:57:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-handle: anExternalAddress
- handle := anExternalAddress.
- CPrimitives cairo_scaled_font_reference: handle.
- self registerForFinalization.
- extents := FontExtents new.
- CPrimitives cairo_scaled_font_extents: handle _: extents
-
- "Created: / 09-01-2015 / 15:15:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-release
- self unregisterForFinalization.
- ^self destroy
-
- "Created: / 28-12-2014 / 23:49:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 09-01-2015 / 10:23:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!ScaledFont methodsFor:'queries-dimensions'!
-
-ascent
- "return the ascent - the number of pixels above the baseLine."
-
- ^ extents ascent
-
- "Created: / 09-01-2015 / 15:33:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-descent
- "return the descent - the number of pixels below the baseLine."
-
- ^ extents descent
-
- "Created: / 09-01-2015 / 15:33:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-height
- "return the height - the number of pixels above plus below the baseLine."
-
- ^ extents height
-
- "Created: / 09-01-2015 / 15:33:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-isFixedWidth
- "return true, if this is a fixed pitch font (i.e. all characters
- are of the same width)"
-
- ^ false
-
- "Created: / 09-01-2015 / 15:35:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-maxAscent
- "return the fonts maximum-ascent (i.e. the maximum of all characters);
- That is the number of units (usually pixels) above the baseline."
-
- ^ self ascent
-
- "Created: / 09-01-2015 / 15:34:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-maxDescent
- "return the fonts maximum-descent (i.e. the maximum of all characters);
- That is the number of units (usually pixels) below the baseline."
-
- ^ self descent
-
- "Created: / 09-01-2015 / 15:34:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-maxWidth
- "return the fonts maximum-width character (i.e. the maximum of all characters);
- That is a number of units (usually pixels)."
-
- ^ extents maxXAdvance
-
- "Created: / 09-01-2015 / 15:35:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-widthOf:aString from:start to:stop
- "return the width of a sub string"
-
- | str extents width |
-
- (start == 1 and: [ stop == aString size ]) ifTrue:[
- str := aString
- ] ifFalse:[
- str := aString copyFrom: start to: stop.
- ].
- extents := TextExtents new.
- Cairo::CPrimitives cairo_scaled_font_text_extents: handle _: str utf8Encoded _: extents.
- width := extents width.
- extents free.
- ^ width
-
- "Created: / 09-01-2015 / 15:28:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 17-02-2016 / 06:39:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!ScaledFont class methodsFor:'documentation'!
@@ -220,5 +116,3 @@
^ '$Changeset: <not expanded> $'
! !
-
-ScaledFont initialize!