Skip to content

Commit

Permalink
Merge branch 'dev' into CacheFonts
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchodias committed May 3, 2024
2 parents ff27356 + e48b87f commit d73296f
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 111 deletions.
16 changes: 14 additions & 2 deletions src/Alexandrie-Base-Tests/AePixelMatchTest.class.st
Expand Up @@ -33,10 +33,22 @@ AePixelMatchTest class >> allPixelComparisons [
{ #category : #'building suites' }
AePixelMatchTest class >> buildSuite [

^ self buildSuiteForAll: self allFormSelectors
]

{ #category : #'building suites' }
AePixelMatchTest class >> buildSuiteFor: aFormSelector [

^ self buildSuiteForAll: { aFormSelector }
]

{ #category : #'building suites' }
AePixelMatchTest class >> buildSuiteForAll: formSelectors [

| suite |
suite := self suiteClass named: self name.
self allFormSelectors do: [ :each |

formSelectors do: [ :each |
| tmpSuite |
tmpSuite := self buildSuiteFromSelectors.
tmpSuite tests do: [ :aTest | aTest formSelector: each ].
Expand Down
25 changes: 23 additions & 2 deletions src/Alexandrie-Cairo-Tests/AeCairoContextTest.class.st
Expand Up @@ -17,6 +17,12 @@ AeCairoContextTest >> newSourceSansProRegularFontFace [
^ AeCairoFreetypeFontFace newForFace: aFTFace
]

{ #category : #accessing }
AeCairoContextTest >> resources [

^ { AeFTLibraryResource }
]

{ #category : #tests }
AeCairoContextTest >> testClipExtents [

Expand Down Expand Up @@ -136,7 +142,7 @@ AeCairoContextTest >> testFontExtents [
aContext := aSurface newContext.

"Set up scaled font in the context"
aFontFace := self newSourceSansProRegularFontFace.
aFontFace := AeFTLibraryResource current sourceSansProRegularFTFace newCairoFontFace.
aContext
fontFace: aFontFace;
fontSize: 17.
Expand Down Expand Up @@ -177,7 +183,7 @@ AeCairoContextTest >> testGlyphExtentsOf [
string := 'Hola'.

"Set up scaled font in the context"
aFontFace := self newSourceSansProRegularFontFace.
aFontFace := AeFTLibraryResource current sourceSansProRegularFTFace newCairoFontFace.
aContext
fontFace: aFontFace;
fontSize: 17.
Expand Down Expand Up @@ -207,6 +213,21 @@ AeCairoContextTest >> testGlyphExtentsOf [
self assert: aTextExtents advance closeTo: 34@0
]

{ #category : #tests }
AeCairoContextTest >> testLineWidth [

surface := AeCairoImageSurface extent: 1@1.
context := surface newContext.

"Assert on default value"
self assert: context lineWidth equals: 2.0.

context lineWidth: 7.

"Assert on new value"
self assert: context lineWidth equals: 7.0
]

{ #category : #tests }
AeCairoContextTest >> testOperator [

Expand Down
60 changes: 21 additions & 39 deletions src/Alexandrie-Cairo-Tests/AeCairoExamplesRenderTest.class.st
Expand Up @@ -25,13 +25,19 @@ AeCairoExamplesRenderTest class >> inspectMismatches [
super inspectMismatches
]

{ #category : #accessing }
AeCairoExamplesRenderTest >> resources [

^ { AeFTLibraryResource }
]

{ #category : #tests }
AeCairoExamplesRenderTest >> surfaceWithAllOperators [
"Catalog of cairo's compositing operators.
See: https://www.cairographics.org/operators/"

| operators fontSize rectangleExtent rectangleOffset margin rowHeight aSurface aContext aFTLibrary aFTFace aFontFace |
| operators fontSize rectangleExtent rectangleOffset margin rowHeight aSurface aContext aFTFace aFontFace |
operators := AeCairoOperator allValues.
margin := 3.
fontSize := 8.
Expand All @@ -45,9 +51,8 @@ AeCairoExamplesRenderTest >> surfaceWithAllOperators [
aContext := aSurface newContext.

"Set up text"
aFTLibrary := AeFTLibrary newInitialized.
aFTFace := AeSourceSansPro_Regular firstFaceUsing: aFTLibrary.
aFontFace := AeCairoFreetypeFontFace newForFace: aFTFace.
aFTFace := AeFTLibraryResource current sourceSansProRegularFTFace.
aFontFace := aFTFace newCairoFontFace.
aContext
fontFace: aFontFace;
fontSize: fontSize.
Expand Down Expand Up @@ -88,7 +93,7 @@ AeCairoExamplesRenderTest >> surfaceWithAllOperators [
AeCairoExamplesRenderTest >> surfaceWithColoredIcons [

| inputForm inputSurface outputColors outputSurface outputContext |
inputForm := self iconNamed: #windowClose.
inputForm := Form fromFileNamed: AeFilesystemResources removeIconPNG.
inputSurface := AeCairoImageSurface fromForm: inputForm.

outputColors := Color wheel: 7.
Expand Down Expand Up @@ -347,7 +352,7 @@ AeCairoExamplesRenderTest >> surfaceWithGouraudBasedTriangle [
AeCairoExamplesRenderTest >> surfaceWithPixelatedIcon [

| iconForm iconSurface iconPattern scale aSurface aContext |
iconForm := Smalltalk ui icons iconNamed: #removeIcon.
iconForm := Form fromFileNamed: AeFilesystemResources removeIconPNG.
iconSurface := AeCairoImageSurface fromForm: iconForm.
iconPattern := AeCairoSurfacePattern surface: iconSurface.
scale := 5.0.
Expand Down Expand Up @@ -599,10 +604,9 @@ AeCairoExamplesRenderTest >> surfaceWithStraightEdgesCurve [
AeCairoExamplesRenderTest >> surfaceWithStretchedIcon [

| aSurface aContext iconForm iconSurface iconPattern horizontalScale verticalScale |
iconForm := Smalltalk ui icons iconNamed: #classIcon.
self assert: iconForm extent = (16@16).
iconForm := Form fromFileNamed: AeFilesystemResources removeIconPNG.
horizontalScale := 0.5.
verticalScale := 4.0.
verticalScale := 2.0.

iconSurface := AeCairoImageSurface fromForm: iconForm.
iconPattern := AeCairoSurfacePattern surface: iconSurface.
Expand Down Expand Up @@ -631,7 +635,7 @@ AeCairoExamplesRenderTest >> surfaceWithStretchedIcon [
{ #category : #'tests - text' }
AeCairoExamplesRenderTest >> surfaceWithText [

| fontSize string surfaceSize aSurface aContext aFTLibrary aFTFace aScaledFont |
| fontSize string surfaceSize aSurface aContext aFTFace aScaledFont |
fontSize := 12.
"Get Lorem Ipsum without last cr character"
string := (String loremIpsum: 28) allButLast.
Expand All @@ -647,8 +651,7 @@ AeCairoExamplesRenderTest >> surfaceWithText [
paint.

"Set up scaled font in the context"
aFTLibrary := AeFTLibrary newInitialized.
aFTFace := AeSourceSansPro_Regular firstFaceUsing: aFTLibrary.
aFTFace := AeFTLibraryResource current sourceSansProRegularFTFace.
aContext
fontFace: (AeCairoFreetypeFontFace newForFace: aFTFace);
fontSize: fontSize.
Expand All @@ -668,7 +671,7 @@ AeCairoExamplesRenderTest >> surfaceWithText [
{ #category : #'tests - text' }
AeCairoExamplesRenderTest >> surfaceWithTextAsPath [

| fontSize string surfaceSize aSurface aContext aFTLibrary aFTFace aFontFace glyphArray debugScaledFont |
| fontSize string surfaceSize aSurface aContext aFTFace aFontFace glyphArray |

fontSize := 25.
string := 'Hola'.
Expand All @@ -679,9 +682,7 @@ AeCairoExamplesRenderTest >> surfaceWithTextAsPath [
aContext := aSurface newContext.

"Set up"
aFTLibrary := AeFTLibrary newInitialized.
50 milliSeconds wait.
aFTFace := AeSourceSansPro_Bold firstFaceUsing: aFTLibrary.
aFTFace := AeFTLibraryResource current sourceSansProBoldFTFace.
aFontFace := AeCairoFreetypeFontFace newForFace: aFTFace.
aContext
sourceColor: Color paleGreen;
Expand All @@ -700,23 +701,6 @@ AeCairoExamplesRenderTest >> surfaceWithTextAsPath [
dash: (AeFFIDoubleArray newFrom: { 7. 1 }) offset: 3;
lineWidth: 1.5;
stroke.



"Debugging a random failure..."
Stdio stdout
<< #surfaceWithTextAsPath; lf;
<< (aContext glyphExtentsOf: glyphArray) asString; lf.
debugScaledFont := aFontFace
newScaledFontWithFontMatrix: (AeCairoMatrix newScalingBy: fontSize asPoint)
userToDeviceMatrix: AeCairoMatrix newIdentity
options: AeCairoFontOptions new.
Stdio stdout << (debugScaledFont glyphExtentsOf: glyphArray) asString; lf.
glyphArray := debugScaledFont glyphArrayForString: string.
Stdio stdout << (debugScaledFont glyphExtentsOf: glyphArray) asString; lf.




^ aSurface
]
Expand All @@ -729,7 +713,7 @@ AeCairoExamplesRenderTest >> surfaceWithTextPixelated [
- Convert the group to a pattern, to customize its filter and matrix
- Finally, paint the pattern on the surface"

| zoom fontSize surfaceSize string aSurface aContext aFTLibrary aFTFace aScaledFont aGlyphArray aFontOptions aFontFace aPattern |
| zoom fontSize surfaceSize string aSurface aContext aFTFace aScaledFont aGlyphArray aFontOptions aFontFace aPattern |
fontSize := 17.
zoom := 2.
string := 'aeiou'.
Expand All @@ -740,8 +724,7 @@ AeCairoExamplesRenderTest >> surfaceWithTextPixelated [
aContext := aSurface newContext.

"Set up aScaleFont"
aFTLibrary := AeFTLibrary newInitialized.
aFTFace := AeSourceSansPro_Regular firstFaceUsing: aFTLibrary.
aFTFace := AeFTLibraryResource current sourceSansProRegularFTFace.
aFontOptions := AeCairoFontOptions new
antialias: AeCairoAntialias none;
hintStyle: AeCairoHintStyle full;
Expand Down Expand Up @@ -810,7 +793,7 @@ AeCairoExamplesRenderTest >> surfaceWithToyAPISelectFontSlantWeight [
AeCairoExamplesRenderTest >> surfaceWithToyAPIShowText [
"Use `AeCairoContext>>#showText:`, which cairo documentation considers 'toy API'."

| string fontSize aSurface aContext aFTLibrary aFTFace aFontFace |
| string fontSize aSurface aContext aFTFace aFontFace |
string := ''.
fontSize := 25.
aSurface := AeCairoImageSurface
Expand All @@ -819,8 +802,7 @@ AeCairoExamplesRenderTest >> surfaceWithToyAPIShowText [
aContext := aSurface newContext.

"Set up a font"
aFTLibrary := AeFTLibrary newInitialized.
aFTFace := AeSourceSansPro_Bold firstFaceUsing: aFTLibrary.
aFTFace := AeFTLibraryResource current sourceSansProBoldFTFace.
aFontFace := AeCairoFreetypeFontFace newForFace: aFTFace.

aContext
Expand Down
19 changes: 8 additions & 11 deletions src/Alexandrie-Cairo-Tests/AeCairoFreetypeTest.class.st
Expand Up @@ -13,15 +13,20 @@ Class {
#category : #'Alexandrie-Cairo-Tests'
}

{ #category : #accessing }
AeCairoFreetypeTest >> resources [

^ { AeFTLibraryResource }
]

{ #category : #running }
AeCairoFreetypeTest >> setUp [
super setUp.

cairoSurface := AeCairoImageSurface extent: 100 @ 20.
cairoContext := cairoSurface newContext.

aFTLibrary := AeFTLibrary newInitialized.
aFTFace := AeSourceSansPro_Regular firstFaceUsing: aFTLibrary.

aFTFace := AeFTLibraryResource current sourceSansProRegularFTFace.
aFontFace := AeCairoFreetypeFontFace newForFace: aFTFace.
aFontMatrix := AeCairoMatrix newScalingByX: 10 y: 15.
aScaledFont := aFontFace
Expand All @@ -31,14 +36,6 @@ AeCairoFreetypeTest >> setUp [

]

{ #category : #running }
AeCairoFreetypeTest >> tearDown [

{ aScaledFont. aFontFace. aFTFace. aFTLibrary } do: #externallyFree.

super tearDown
]

{ #category : #tests }
AeCairoFreetypeTest >> testFontMatrix [

Expand Down
Expand Up @@ -41,7 +41,7 @@ AeCairoImageSurfaceTest >> testExtentFormat [
AeCairoImageSurfaceTest >> testFromForm [

| aForm |
aForm := Smalltalk ui icons iconNamed: #classIcon.
aForm := Form fromFileNamed: AeFilesystemResources removeIconPNG.
surface := AeCairoImageSurface fromForm: aForm.

self assert: surface extent equals: aForm extent
Expand Down
12 changes: 12 additions & 0 deletions src/Alexandrie-Cairo-Tests/AeFilesystemResources.extension.st
Expand Up @@ -5,3 +5,15 @@ AeFilesystemResources class >> cairoDirectory [

^ self testsDirectory / 'cairo'
]

{ #category : #'*Alexandrie-Cairo-Tests' }
AeFilesystemResources class >> imagesDirectory [

^ self testsDirectory / 'images'
]

{ #category : #'*Alexandrie-Cairo-Tests' }
AeFilesystemResources class >> removeIconPNG [

^ self imagesDirectory / 'removeIcon.png'
]

0 comments on commit d73296f

Please sign in to comment.