Skip to content

Commit

Permalink
Add openTypeFeatureTags
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchodias committed Dec 13, 2023
1 parent 3b20fe4 commit 13f174f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Alexandrie-Harfbuzz/AeHbFace.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ AeHbFace >> allOpenTypePredefinedNamesAsDictionary [
^ result
]

{ #category : #accessing }
AeHbFace >> getOpenTypeFeatureTagsAt: tag offset: offset into: featuresAddress size: featureSizeAddress [
"Fetches a list of all feature tags in the given face's GSUB or GPOS table. Note that there might be duplicate feature tags, belonging to different script/language-system pairs of the table.
See: https://harfbuzz.github.io/harfbuzz-hb-ot-layout.html#hb-ot-layout-table-get-feature-tags"

^ self ffiCall: #(
uint
hb_ot_layout_table_get_feature_tags (
self,
hb_tag_t tag,
uint offset,
uint * featureSizeAddress,
void * featuresAddress )
)
]

{ #category : #accessing }
AeHbFace >> getOpenTypeUtf8Name: nameId into: text num: textSize language: language [
"See: https://harfbuzz.github.io/harfbuzz-hb-ot-name.html#hb-ot-name-get-utf8"
Expand Down Expand Up @@ -181,6 +198,41 @@ AeHbFace >> newHbFont [
^ AeHbFont newForHbFace: self
]

{ #category : #accessing }
AeHbFace >> openTypeFeatureTags [

| featureTags featureTagsSize features |
self flag: #todo. "Iteration does not work well (try reducing the array's size)"
featureTags := FFIExternalArray newType: FFIUInt32 size: 5000.
featureTagsSize := FFIUInt32 newBuffer.
featureTagsSize unsignedLongAt: 1 put: featureTags size.
features := OrderedCollection new.

#('GSUB' 'GPOS') do: [ :eachTag |
| actualSize offset atEnd |
offset := 0.
[ actualSize :=
self
getOpenTypeFeatureTagsAt: eachTag asHbTagInteger
offset: offset
into: featureTags getHandle
size: featureTagsSize.

featureTags size + offset >= actualSize
ifTrue: [
atEnd := true.
1 to: actualSize - offset do: [ :i |
features add: (featureTags at: i) ] ]
ifFalse: [
atEnd := false.
features addAll: featureTags.
offset := offset + featureTags size ]

] doWhileFalse: [ atEnd ] ].

^ features collect: #asHbTagString
]

{ #category : #accessing }
AeHbFace >> openTypeFontFamily [

Expand Down
13 changes: 13 additions & 0 deletions src/Alexandrie-HarfbuzzCairo/AeHbCairoFeaturesExample.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ AeHbCairoFeaturesExample class >> exampleDraw: aString features: featuresExterna
inspectWithLabel: featuresExternalArray asString
]

{ #category : #examples }
AeHbCairoFeaturesExample class >> exampleDrawAllFeaturesInFace [

self newCascadiaFace openTypeFeatureTags asSet asArray sorted do: [ :each |
self
exampleDraw: 'Office''s->1.9/234'
binaryTag: each
font: self newInriaFace newHbFont
fontSize: 20 ].


]

{ #category : #examples }
AeHbCairoFeaturesExample class >> exampleDrawCascadiaArrows [

Expand Down

0 comments on commit 13f174f

Please sign in to comment.