2022-03-01 19:22:26 +01:00
|
|
|
Class {
|
|
|
|
#name : #DiyaFontManager,
|
|
|
|
#superclass : #DiyaSingleton,
|
|
|
|
#instVars : [
|
|
|
|
'families'
|
|
|
|
],
|
|
|
|
#category : #'Diya-Fonts'
|
|
|
|
}
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaFontManager class >> cleanUpInstance: singleton [
|
2022-03-02 20:11:01 +01:00
|
|
|
singleton ifNil:[^self].
|
2022-03-01 19:22:26 +01:00
|
|
|
singleton reset.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'as yet unclassified' }
|
|
|
|
DiyaFontManager class >> searchPaths [
|
|
|
|
^ {
|
|
|
|
Smalltalk imageDirectory / 'fonts'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-03-01 22:58:58 +01:00
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaFontManager >> defaultFamily [
|
2022-03-19 02:18:29 +01:00
|
|
|
^'Ubuntu'
|
2022-03-01 22:58:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2022-03-01 19:22:26 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaFontManager >> families [
|
|
|
|
^ families
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaFontManager >> familyNames [
|
|
|
|
^ families keys
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaFontManager >> initialize [
|
|
|
|
super initialize.
|
|
|
|
families := Dictionary new.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaFontManager >> loadFace: face [
|
|
|
|
|family|
|
|
|
|
family := families at: face familyName ifAbsentPut:[DiyaFontFamily fromFace: face].
|
|
|
|
family addFace: face
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaFontManager >> loadFile: aFile [
|
|
|
|
| path face i numfaces |
|
|
|
|
path := aFile fullName convertToWithConverter: UTF8TextConverter new.
|
2022-03-15 19:29:57 +01:00
|
|
|
Transcript show: 'Loading font file ', path;cr.
|
2022-03-01 19:22:26 +01:00
|
|
|
i := 0.
|
|
|
|
numfaces := nil.
|
|
|
|
[ face := FreeTypeFace basicNew
|
|
|
|
filename: path;
|
|
|
|
index: i.
|
|
|
|
face newFaceFromFile: path index: i.
|
|
|
|
face loadFields.
|
2022-03-15 19:29:57 +01:00
|
|
|
Transcript show: 'Loaded font face ', face styleName;cr.
|
2022-03-01 19:22:26 +01:00
|
|
|
numfaces ifNil: [ numfaces := face numFaces ].
|
|
|
|
self loadFace: face.
|
|
|
|
i := i + 1.
|
2022-03-19 02:18:29 +01:00
|
|
|
i < numfaces ] whileTrue
|
2022-03-01 19:22:26 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaFontManager >> loadFonts [
|
|
|
|
self loadFonts: false.
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaFontManager >> loadFonts: force [
|
|
|
|
force ifTrue:[self reset].
|
|
|
|
self class searchPaths do:[:path| self loadPath: path].
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaFontManager >> loadPath: path [
|
|
|
|
path entries do:[:entry| entry isFile ifTrue:[self loadFile: entry ]].
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaFontManager >> reset [
|
|
|
|
"reset all stored faces"
|
|
|
|
families := Dictionary new.
|
|
|
|
]
|
2022-03-04 20:28:38 +01:00
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaFontManager >> style: styleName from: familyName [
|
|
|
|
|family|
|
|
|
|
family := families at: familyName ifAbsent: [ self defaultFamily ].
|
|
|
|
^family style: styleName
|
|
|
|
|
|
|
|
]
|