Skip to content
50 changes: 38 additions & 12 deletions src/Bloc-Alexandrie/BAFontConverter.class.st
Original file line number Diff line number Diff line change
@@ -1,46 +1,73 @@
"
I convert from a BlFont to a Cairo font.
"
Class {
#name : #BAFontConverter,
#superclass : #Object,
#instVars : [
'slantTranslator',
'stretchTranslator',
'weightTranslator'
'slantConverter',
'weightConverter',
'stretchConverter'
],
#classInstVars : [
'uniqueInstance'
],
#category : #'Bloc-Alexandrie-Text'
}

{ #category : #accessing }
BAFontConverter class >> reset [
<script>

uniqueInstance := nil
]

{ #category : #accessing }
BAFontConverter class >> uniqueInstance [

^ uniqueInstance ifNil: [ uniqueInstance := self new ]
]

{ #category : #initialization }
BAFontConverter >> aeSlantAt: fontSlant [

^ slantConverter at: fontSlant
]

{ #category : #initialization }
BAFontConverter >> aeStretchAt: fontStretch [

^ stretchConverter at: fontStretch
]

{ #category : #initialization }
BAFontConverter >> aeWeightAt: fontWeight [

^ weightConverter at: fontWeight
]

{ #category : #initialization }
BAFontConverter >> faceFor: aBlFont [

^ AeFontManager globalInstance
detectFamilyName: aBlFont familyName
slant: (slantTranslator at: aBlFont fontSlant)
weight: (weightTranslator at: aBlFont fontWeight)
stretch: (stretchTranslator at: aBlFont fontStretch)
slant: (self aeSlantAt: aBlFont fontSlant)
weight: (self aeWeightAt: aBlFont fontWeight)
stretch: (self aeStretchAt: aBlFont fontStretch)
ifNone: [ AeFontManager globalInstance defaultFace ]

]

{ #category : #initialization }
BAFontConverter >> initialize [

super initialize.

slantTranslator := IdentityDictionary new
slantConverter := IdentityDictionary new
at: BlFontSlant normal put: AeFontSlant normal;
at: BlFontSlant italic put: AeFontSlant italic;
at: BlFontSlant oblique put: AeFontSlant oblique;
yourself.
stretchTranslator := IdentityDictionary new
stretchConverter := IdentityDictionary new
at: BlFontStretch ultraCondensed put: AeFontStretch ultraCondensed;
at: BlFontStretch extraCondensed put: AeFontStretch extraCondensed;
at: BlFontStretch condensed put: AeFontStretch condensed;
Expand All @@ -51,7 +78,7 @@ BAFontConverter >> initialize [
at: BlFontStretch extraExpanded put: AeFontStretch extraExpanded;
at: BlFontStretch ultraExpanded put: AeFontStretch ultraExpanded;
yourself.
weightTranslator := IdentityDictionary new
weightConverter := IdentityDictionary new
at: BlFontWeight thin put: AeFontWeight thin;
at: BlFontWeight extraLight put: AeFontWeight extraLight;
at: BlFontWeight light put: AeFontWeight light;
Expand All @@ -61,6 +88,5 @@ BAFontConverter >> initialize [
at: BlFontWeight bold put: AeFontWeight bold;
at: BlFontWeight extraBold put: AeFontWeight extraBold;
at: BlFontWeight black put: AeFontWeight black;
yourself.

yourself
]
21 changes: 9 additions & 12 deletions src/Bloc-Alexandrie/BAMockedTextParagraphSpan.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ Class {
{ #category : #drawing }
BAMockedTextParagraphSpan >> aeDrawOn: aeCanvas [

| characterWidth characterHeight aBlFont aFace |
| characterWidth characterHeight |
self spanLength isZero ifTrue: [ ^ self ].

aBlFont := fontAndStyleBuilder font.
aFace := aBlFont asAeFTFace.
cairoScaledFont := aeCanvas
scaledFontForFace: aFace
size: aBlFont fontSize value.
cairoScaledFont := fontAndStyleBuilder aeCairoScaledFontOn: aeCanvas.

"Get glyphs for the text"
characterWidth := (self width / self spanLength) asFloat.
Expand All @@ -34,9 +30,10 @@ BAMockedTextParagraphSpan >> aeDrawOn: aeCanvas [
measuredHeight isZero ifTrue: [ measuredHeight := characterHeight ].
heightScale := characterHeight * 0.8 / measuredHeight.
fixedBounds := eachBaseline extent: characterWidth @ characterHeight.
aeCanvas setSourceColor: (fontAndStyleBuilder hasCustomColor
ifTrue: [ fontAndStyleBuilder color ]
ifFalse: [ Color black ]).
aeCanvas setSourceColor:
(fontAndStyleBuilder hasCustomColor
ifTrue: [ fontAndStyleBuilder color ]
ifFalse: [ Color black ]).

"Draw the border around the character"
aeCanvas restoreContextAfter: [
Expand Down Expand Up @@ -64,9 +61,9 @@ BAMockedTextParagraphSpan >> aeDrawOn: aeCanvas [
aeCanvas restoreContextAfter: [
| idxScaledFont idxGlyphsArray |
aeCanvas setSourceColor: Color gray.
idxScaledFont := aeCanvas
scaledFontForFace: aFace
size: characterHeight * 0.32.
idxScaledFont := fontAndStyleBuilder copy
fontSize: characterHeight * 0.32;
aeCairoScaledFontOn: aeCanvas.
idxGlyphsArray := idxScaledFont glyphArrayForString: (index + hostMeasurer textOffset - 1) asString.
index = 1 ifTrue: [
aeCanvas restoreContextAfter: [
Expand Down
22 changes: 6 additions & 16 deletions src/Bloc-Alexandrie/BATextParagraphSpan.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ BATextParagraphSpan >> aeDrawOn: aeCanvas [
self span ifNil: [ ^ self ].
aeCanvas restoreContextAfter: [
aeCanvas pathTranslate: self baseline.
self flag: #todo. "Default color?"
aeCanvas setSourceColor: (fontAndStyleBuilder hasCustomColor

aeCanvas setSourceColor:
(fontAndStyleBuilder hasCustomColor
ifTrue: [ fontAndStyleBuilder color ]
ifFalse: [ Color black ]).

Expand All @@ -35,27 +36,16 @@ BATextParagraphSpan >> appendPathOn: aeCanvas [

{ #category : #building }
BATextParagraphSpan >> measure [

"build an abstract font and resolve not yet resolved properties"

| metrics canvas font usedSpan fontSize face |
| metrics canvas usedSpan |
canvas := hostMeasurer canvas.

usedSpan := self span isTabulation
ifTrue: [ '' ]
ifFalse: [ self span ].
usedSpan := self span isTabulation ifTrue: [ '' ] ifFalse: [ self span ].

font := fontAndStyleBuilder font.
fontSize := font fontSize value.
face := font asAeFTFace.
cairoScaledFont := canvas scaledFontForFace: face size: fontSize.

"Without Harfbuzz:"
cairoScaledFont := fontAndStyleBuilder aeCairoScaledFontOn: canvas.
cairoGlyphsArray := cairoScaledFont glyphArrayForString: usedSpan.

"With Harfbuzz:"
"cairoGlyphsArray := AeHbBuffer defaultCairoGlyphArrayFor: usedSpan face: face size: fontSize."

metrics := canvas metricsFor: cairoGlyphsArray font: cairoScaledFont.
baseline := 0 @ 0.
ascent := metrics ascent.
Expand Down
4 changes: 3 additions & 1 deletion src/Bloc-Alexandrie/BlFont.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ Extension { #name : #BlFont }
{ #category : #'*Bloc-Alexandrie' }
BlFont >> asAeFTFace [

^ BAFontConverter uniqueInstance faceFor: self
self deprecated: 'Migrate our code to #asAeCairoFontFace'.

^ self error
]
7 changes: 4 additions & 3 deletions src/Bloc-Alexandrie/BlSideBackgroundDecoration.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ Extension { #name : #BlSideBackgroundDecoration }
{ #category : #'*Bloc-Alexandrie' }
BlSideBackgroundDecoration >> aeCairoScaledFontOn: aeCanvas in: anInfiniteElement [

| fontAndStyleBuilder freeTypeFont |
| fontAndStyleBuilder |
fontAndStyleBuilder := BlTextFontAndStyleBuilder new.
freeTypeFont := fontAndStyleBuilder font asAeFTFace.
^ aeCanvas scaledFontForFace: freeTypeFont size: 12
fontAndStyleBuilder fontSize: 12.

^ fontAndStyleBuilder aeCairoScaledFontOn: aeCanvas
]

{ #category : #'*Bloc-Alexandrie' }
Expand Down
22 changes: 22 additions & 0 deletions src/Bloc-Alexandrie/BlTextFontAndStyleBuilder.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Extension { #name : #BlTextFontAndStyleBuilder }

{ #category : #'*Bloc-Alexandrie' }
BlTextFontAndStyleBuilder >> aeCairoScaledFontOn: aeCanvas [

^ aeCanvas
scaledFontForFamily: (self hasCustomFamilyName
ifTrue: [ self resolvedFontFamilyName ]
ifFalse: [ BlFont defaultFamilyName ])
size: (self hasCustomFontSize
ifTrue: [ self resolvedFontSize value ]
ifFalse: [ BlFont defaultFontSize ])
slant: (self hasCustomFontSlant
ifTrue: [ BAFontConverter uniqueInstance aeSlantAt: self fontSlant ]
ifFalse: [ AeFontSlant normal ])
weight: (self hasCustomFontWeight
ifTrue: [ BAFontConverter uniqueInstance aeWeightAt: self fontWeight ]
ifFalse: [ AeFontWeight normal ])
stretch: (self hasCustomFontStretch
ifTrue: [ BAFontConverter uniqueInstance aeStretchAt: self fontStretch ]
ifFalse: [ AeFontStretch normal ])
]
Binary file modified tests/hit/buildGaussianShadowsByTextTransformations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/hit/buildSimpleShadowsByTextTransformations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/hit/buildTextAttributes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/hit/buildTextMeasurements.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/hit/buildTextOpacities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/hit/buildTextTransformations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/hit/buildTextWithBorder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/hit/buildTextWithOverlappingBorder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/render/buildGaussianShadowsByTextTransformations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/render/buildSimpleShadowsByTextTransformations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/render/buildTextAttributes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/render/buildTextMeasurements.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/render/buildTextOpacities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/render/buildTextTransformations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/render/buildTextWithBorder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/render/buildTextWithBorderAbove.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/render/buildTextWithDashedBorder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/render/buildTextWithOverlappingBorder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading