Skip to content

Commit

Permalink
We need to create a copy of the freeTypeFont so it does not mix with …
Browse files Browse the repository at this point in the history
…the use it has from Cairo.
  • Loading branch information
tesonep committed Jul 3, 2020
1 parent 4aaee8c commit 643acad
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Athens-Cairo/CairoFontFace.class.st
Expand Up @@ -24,7 +24,7 @@ CairoFontFace class >> countReferences: handle [
"
unsigned int cairo_font_face_get_reference_count (cairo_font_face_t *font_face);
"
^ self ffiCall: #( unsigned int cairo_font_face_get_reference_count (size_t handle))
^ self ffiCall: #( uint cairo_font_face_get_reference_count (size_t handle))
]

{ #category : #finalizing }
Expand Down
40 changes: 31 additions & 9 deletions src/Athens-Cairo/CairoScaledFont.class.st
Expand Up @@ -9,7 +9,8 @@ Class {
#traits : 'TCairoLibrary',
#classTraits : 'TCairoLibrary classTrait',
#instVars : [
'face'
'face',
'freeTypeFont'
],
#pools : [
'AthensCairoDefinitions'
Expand All @@ -31,13 +32,10 @@ CairoScaledFont class >> fromFreetypeFont: aFont [
| ftFace face |
^ CairoBackendCache soleInstance at: aFont ifAbsentPut: [ | emphasis |
emphasis := aFont simulatedEmphasis.
ftFace := aFont face.
face := CairoBackendCache soleInstance
at: {ftFace. emphasis}
ifAbsentPut: [ | cff |
cff := CairoFontFace fromFreetypeFace: ftFace.
emphasis ifNotNil: [ cff synthesizeEmphasis: emphasis ].
cff ].
"I will copy it, as it used by cairo"
ftFace := aFont face copy.
face := CairoFontFace fromFreetypeFace: ftFace.
emphasis ifNotNil: [ face synthesizeEmphasis: emphasis ].
self fromFreetypeFont: aFont cairoFace: face ]
]

Expand All @@ -56,7 +54,9 @@ CairoScaledFont class >> fromFreetypeFont: aFont cairoFace: face [
font := self primCreate: face fontMatrix: fontMatrix userToDeviceMatrix: deviceMatrix options: options.

"to keep a reference to cairo face in instance"
^ font initWithFace: face.
^ (font initWithFace: face)
freeTypeFont: aFont;
yourself.


]
Expand Down Expand Up @@ -106,6 +106,12 @@ CairoScaledFont >> extents [
^ extents
]

{ #category : #accessing }
CairoScaledFont >> freeTypeFont: aFreeTypeFont [

freeTypeFont := aFreeTypeFont
]

{ #category : #accessing }
CairoScaledFont >> getExtents: cairoFontExtents [
"void cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font,
Expand Down Expand Up @@ -142,6 +148,22 @@ CairoScaledFont >> getExtentsOfGlyphs: glyphs ofLength: num into: extents [

]

{ #category : #accessing }
CairoScaledFont >> getFontMatrixInto: cairoFontMatrix [
^ self ffiCall: #(
void
cairo_scaled_font_get_font_matrix (self,
AthensCairoMatrix *cairoFontMatrix))
]

{ #category : #accessing }
CairoScaledFont >> getFontScaleMatrixInto: cairoFontMatrix [
^ self ffiCall: #(
void
cairo_scaled_font_get_scale_matrix (self,
AthensCairoMatrix *cairoFontMatrix))
]

{ #category : #initialization }
CairoScaledFont >> initWithFace: cairo_face [

Expand Down
9 changes: 9 additions & 0 deletions src/FreeType/FreeTypeFace.class.st
Expand Up @@ -129,6 +129,15 @@ FreeTypeFace >> index: anInteger [
index := anInteger
]

{ #category : #copying }
FreeTypeFace >> postCopy [

handle beNull.
self validate.
self autoRelease.
^ self
]

{ #category : #caching }
FreeTypeFace >> releaseCachedState [

Expand Down

0 comments on commit 643acad

Please sign in to comment.