Skip to content

Commit b942daf

Browse files
committed
[harfbuzz] simplify code
1 parent 95f7131 commit b942daf

File tree

9 files changed

+29
-47
lines changed

9 files changed

+29
-47
lines changed

harfbuzz/ot_shape.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func (c *otContext) otRotateChars() {
391391
rtlmMask := c.plan.rtlmMask
392392

393393
for i := range info {
394-
codepoint := uni.mirroring(info[i].codepoint)
394+
codepoint := ucd.LookupMirrorChar(info[i].codepoint)
395395
if codepoint != info[i].codepoint && c.font.hasGlyph(codepoint) {
396396
info[i].codepoint = codepoint
397397
} else {

harfbuzz/ot_shape_arabic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func applyArabicJoining(buffer *Buffer) {
280280

281281
// check pre-context
282282
for _, u := range buffer.context[0] {
283-
thisType := getJoiningType(u, uni.generalCategory(u))
283+
thisType := getJoiningType(u, ucd.LookupGeneralCategory(u))
284284

285285
if thisType == joiningTypeT {
286286
continue
@@ -324,7 +324,7 @@ func applyArabicJoining(buffer *Buffer) {
324324
}
325325

326326
for _, u := range buffer.context[1] {
327-
thisType := getJoiningType(u, uni.generalCategory(u))
327+
thisType := getJoiningType(u, ucd.LookupGeneralCategory(u))
328328

329329
if thisType == joiningTypeT {
330330
continue

harfbuzz/ot_shape_complex.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package harfbuzz
33
import (
44
ot "github.com/go-text/typesetting/font/opentype"
55
"github.com/go-text/typesetting/font/opentype/tables"
6+
ucd "github.com/go-text/typesetting/internal/unicodedata"
67
"github.com/go-text/typesetting/language"
78
)
89

@@ -183,11 +184,11 @@ func (complexShaperNil) collectFeatures(plan *otShapePlanner) {}
183184
func (complexShaperNil) overrideFeatures(plan *otShapePlanner) {}
184185
func (complexShaperNil) dataCreate(plan *otShapePlan) {}
185186
func (complexShaperNil) decompose(_ *otNormalizeContext, ab rune) (a, b rune, ok bool) {
186-
return uni.decompose(ab)
187+
return ucd.Decompose(ab)
187188
}
188189

189190
func (complexShaperNil) compose(_ *otNormalizeContext, a, b rune) (ab rune, ok bool) {
190-
return uni.compose(a, b)
191+
return ucd.Compose(a, b)
191192
}
192193
func (complexShaperNil) preprocessText(*otShapePlan, *Buffer, *Font) {}
193194
func (complexShaperNil) postprocessGlyphs(*otShapePlan, *Buffer, *Font) {

harfbuzz/ot_shape_hebrew.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package harfbuzz
33
import (
44
ot "github.com/go-text/typesetting/font/opentype"
55
"github.com/go-text/typesetting/font/opentype/tables"
6+
ucd "github.com/go-text/typesetting/internal/unicodedata"
67
)
78

89
// ported from harfbuzz/src/hb-ot-shape-complex-hebrew.cc Copyright © 2010,2012 Google, Inc. Behdad Esfahbod
@@ -48,7 +49,7 @@ var sDageshForms = [0x05EA - 0x05D0 + 1]rune{
4849
}
4950

5051
func (complexShaperHebrew) compose(c *otNormalizeContext, a, b rune) (rune, bool) {
51-
ab, found := uni.compose(a, b)
52+
ab, found := ucd.Compose(a, b)
5253

5354
if !found && !c.plan.hasGposMark {
5455
/* Special-case Hebrew presentation forms that are excluded from

harfbuzz/ot_shape_indic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,12 +1392,12 @@ func (cs *complexShaperIndic) decompose(c *otNormalizeContext, ab rune) (rune, r
13921392
*/
13931393
}
13941394

1395-
return uni.decompose(ab)
1395+
return ucd.Decompose(ab)
13961396
}
13971397

13981398
func (cs *complexShaperIndic) compose(c *otNormalizeContext, a, b rune) (rune, bool) {
13991399
/* Avoid recomposing split matras. */
1400-
if uni.generalCategory(a).IsMark() {
1400+
if ucd.LookupGeneralCategory(a).IsMark() {
14011401
return 0, false
14021402
}
14031403

@@ -1406,7 +1406,7 @@ func (cs *complexShaperIndic) compose(c *otNormalizeContext, a, b rune) (rune, b
14061406
return 0x09DF, true
14071407
}
14081408

1409-
return uni.compose(a, b)
1409+
return ucd.Compose(a, b)
14101410
}
14111411

14121412
func (complexShaperIndic) marksBehavior() (zeroWidthMarks, bool) {

harfbuzz/ot_shape_khmer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
ot "github.com/go-text/typesetting/font/opentype"
77
"github.com/go-text/typesetting/font/opentype/tables"
8+
ucd "github.com/go-text/typesetting/internal/unicodedata"
89
)
910

1011
// ported from harfbuzz/src/hb-ot-shape-complex-khmer.cc Copyright © 2011,2012 Google, Inc. Behdad Esfahbod
@@ -267,16 +268,16 @@ func (complexShaperKhmer) decompose(c *otNormalizeContext, ab rune) (rune, rune,
267268
return 0x17C1, 0x17C5, true
268269
}
269270

270-
return uni.decompose(ab)
271+
return ucd.Decompose(ab)
271272
}
272273

273274
func (complexShaperKhmer) compose(_ *otNormalizeContext, a, b rune) (rune, bool) {
274275
/* Avoid recomposing split matras. */
275-
if uni.generalCategory(a).IsMark() {
276+
if ucd.LookupGeneralCategory(a).IsMark() {
276277
return 0, false
277278
}
278279

279-
return uni.compose(a, b)
280+
return ucd.Compose(a, b)
280281
}
281282

282283
func (complexShaperKhmer) marksBehavior() (zeroWidthMarks, bool) {

harfbuzz/ot_shape_normalize.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (c *otNormalizeContext) decomposeCurrentCharacter(shortest bool) {
150150
}
151151

152152
if buffer.cur(0).isUnicodeSpace() {
153-
spaceType := uni.spaceFallbackType(u)
153+
spaceType := uniSpaceFallbackType(u)
154154
if spaceGlyph, ok := c.font.face.NominalGlyph(0x0020); spaceType != notSpace && (ok || buffer.Invisible != 0) {
155155
if !ok {
156156
spaceGlyph = buffer.Invisible
@@ -182,7 +182,7 @@ func (c *otNormalizeContext) handleVariationSelectorCluster(end int) {
182182
}
183183
font := c.font
184184
for buffer.idx < end-1 {
185-
if uni.isVariationSelector(buffer.cur(+1).codepoint) {
185+
if uniIsVariationSelector(buffer.cur(+1).codepoint) {
186186
var ok bool
187187
buffer.cur(0).Glyph, ok = font.face.VariationGlyph(buffer.cur(0).codepoint, buffer.cur(+1).codepoint)
188188
if ok {
@@ -203,7 +203,7 @@ func (c *otNormalizeContext) handleVariationSelectorCluster(end int) {
203203
buffer.nextGlyph()
204204
}
205205
// skip any further variation selectors.
206-
for buffer.idx < end && uni.isVariationSelector(buffer.cur(0).codepoint) {
206+
for buffer.idx < end && uniIsVariationSelector(buffer.cur(0).codepoint) {
207207
setGlyph(buffer.cur(0), font)
208208
buffer.nextGlyph()
209209
}
@@ -225,7 +225,7 @@ func (c *otNormalizeContext) decomposeMultiCharCluster(end int, shortCircuit boo
225225
}
226226

227227
for i := buffer.idx; i < end; i++ {
228-
if uni.isVariationSelector(buffer.Info[i].codepoint) {
228+
if uniIsVariationSelector(buffer.Info[i].codepoint) {
229229
c.handleVariationSelectorCluster(end)
230230
return
231231
}

harfbuzz/ot_shape_use.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
ot "github.com/go-text/typesetting/font/opentype"
77
"github.com/go-text/typesetting/font/opentype/tables"
8+
ucd "github.com/go-text/typesetting/internal/unicodedata"
89
)
910

1011
// ported from harfbuzz/src/hb-ot-shape-complex-use.cc Copyright © 2015 Mozilla Foundation. Google, Inc. Jonathan Kew, Behdad Esfahbod
@@ -375,11 +376,11 @@ func (cs *complexShaperUSE) preprocessText(_ *otShapePlan, buffer *Buffer, _ *Fo
375376

376377
func (cs *complexShaperUSE) compose(_ *otNormalizeContext, a, b rune) (rune, bool) {
377378
// avoid recomposing split matras.
378-
if uni.generalCategory(a).IsMark() {
379+
if ucd.LookupGeneralCategory(a).IsMark() {
379380
return 0, false
380381
}
381382

382-
return uni.compose(a, b)
383+
return ucd.Compose(a, b)
383384
}
384385

385386
func (complexShaperUSE) marksBehavior() (zeroWidthMarks, bool) {

harfbuzz/unicode.go

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
ucd "github.com/go-text/typesetting/internal/unicodedata"
55
)
66

7-
// uni exposes some lookup functions for Unicode properties.
8-
var uni = unicodeFuncs{}
9-
107
// generalCategory is an enum value to allow compact storage (see generalCategories)
118
type generalCategory = ucd.GeneralCategory
129

@@ -205,9 +202,7 @@ var modifiedCombiningClass = [256]uint8{
205202
255, /* HB_UNICODE_COMBINING_CLASS_INVALID */
206203
}
207204

208-
type unicodeFuncs struct{}
209-
210-
func (unicodeFuncs) modifiedCombiningClass(u rune) uint8 {
205+
func uniModifiedCombiningClass(u rune) uint8 {
211206
// Reorder SAKOT to ensure it comes after any tone marks.
212207
if u == 0x1A60 {
213208
return 254
@@ -272,20 +267,6 @@ func IsDefaultIgnorable(ch rune) bool {
272267
}
273268
}
274269

275-
func (unicodeFuncs) isDefaultIgnorable(ch rune) bool {
276-
return IsDefaultIgnorable(ch)
277-
}
278-
279-
// retrieves the General Category property for
280-
// a specified Unicode code point, expressed as enumeration value.
281-
func (unicodeFuncs) generalCategory(ch rune) generalCategory { return ucd.LookupGeneralCategory(ch) }
282-
283-
func (unicodeFuncs) isExtendedPictographic(ch rune) bool { return ucd.IsExtendedPictographic(ch) }
284-
285-
// returns the mirroring Glyph code point (for bi-directional
286-
// replacement) of a code point, or itself
287-
func (unicodeFuncs) mirroring(ch rune) rune { return ucd.LookupMirrorChar(ch) }
288-
289270
/* Space estimates based on:
290271
* https://unicode.org/charts/PDF/U2000.pdf
291272
* https://docs.microsoft.com/en-us/typography/develop/character-design-standards/whitespace
@@ -306,7 +287,7 @@ const (
306287
spaceEM6 = 6
307288
)
308289

309-
func (unicodeFuncs) spaceFallbackType(u rune) uint8 {
290+
func uniSpaceFallbackType(u rune) uint8 {
310291
switch u {
311292
// all GC=Zs chars that can use a fallback.
312293
case 0x0020:
@@ -346,17 +327,14 @@ func (unicodeFuncs) spaceFallbackType(u rune) uint8 {
346327
}
347328
}
348329

349-
func (unicodeFuncs) isVariationSelector(r rune) bool {
330+
func uniIsVariationSelector(r rune) bool {
350331
/* U+180B..180D, U+180F MONGOLIAN FREE VARIATION SELECTORs are handled in the
351332
* Arabic shaper. No need to match them here. */
352333
/* VARIATION SELECTOR-1..16 */
353334
/* VARIATION SELECTOR-17..256 */
354335
return (0xFE00 <= r && r <= 0xFE0F) || (0xE0100 <= r && r <= 0xE01EF)
355336
}
356337

357-
func (unicodeFuncs) decompose(ab rune) (a, b rune, ok bool) { return ucd.Decompose(ab) }
358-
func (unicodeFuncs) compose(a, b rune) (rune, bool) { return ucd.Compose(a, b) }
359-
360338
/* Prepare */
361339

362340
func isRegionalIndicator(r rune) bool { return 0x1F1E6 <= r && r <= 0x1F1FF }
@@ -399,7 +377,7 @@ func (b *Buffer) setUnicodeProps() {
399377
}
400378
} else if info[i].isZwj() {
401379
info[i].setContinuation(b)
402-
if i+1 < len(b.Info) && uni.isExtendedPictographic(info[i+1].codepoint) {
380+
if i+1 < len(b.Info) && ucd.IsExtendedPictographic(info[i+1].codepoint) {
403381
i++
404382
info[i].setUnicodeProps(b)
405383
info[i].setContinuation(b)
@@ -520,11 +498,11 @@ func (b *Buffer) ensureNativeDirection() {
520498

521499
// the returned flag must be ORed with the current
522500
func computeUnicodeProps(u rune) (unicodeProp, bufferScratchFlags) {
523-
genCat := uni.generalCategory(u)
501+
genCat := ucd.LookupGeneralCategory(u)
524502
props := unicodeProp(genCat)
525503
var flags bufferScratchFlags
526504
if u >= 0x80 {
527-
if uni.isDefaultIgnorable(u) {
505+
if IsDefaultIgnorable(u) {
528506
flags |= bsfHasDefaultIgnorables
529507
props |= upropsMaskIgnorable
530508
if u == 0x200C {
@@ -555,7 +533,7 @@ func computeUnicodeProps(u rune) (unicodeProp, bufferScratchFlags) {
555533
if genCat.IsMark() {
556534
flags |= bsfHasContinuations
557535
props |= upropsMaskContinuation
558-
props |= unicodeProp(uni.modifiedCombiningClass(u)) << 8
536+
props |= unicodeProp(uniModifiedCombiningClass(u)) << 8
559537
}
560538
}
561539

0 commit comments

Comments
 (0)