Source File
direction.go
Belonging Package
github.com/go-text/typesetting/di
package diimport ()// Direction indicates the layout direction of a piece of text.type Direction uint8const (// DirectionLTR is for Left-to-Right text.DirectionLTR Direction = iota// DirectionRTL is for Right-to-Left text.DirectionRTL// DirectionTTB is for Top-to-Bottom text.DirectionTTB// DirectionBTT is for Bottom-to-Top text.DirectionBTT)const (progression Direction = 1 << iota// axisVertical is the bit for the axis, 0 for horizontal, 1 for verticalaxisVertical// If this flag is set, the orientation is chosen// using the [verticalSideways] flag.// Otherwise, the segmenter will resolve the orientation based// on unicode propertiesverticalOrientationSet// verticalSideways is set for 'sideways', unset for 'upright'// It implies BVerticalOrientationSet is setverticalSideways)// IsVertical returns whether d is laid out on a vertical// axis. If the return value is false, d is on the horizontal// axis.func ( Direction) () bool { return &axisVertical != 0 }// Axis returns the layout axis for d.func ( Direction) () Axis {if .IsVertical() {return Vertical}return Horizontal}// SwitchAxis switches from horizontal to vertical (and vice versa), preserving// the progression.func ( Direction) () Direction { return ^ axisVertical }// Progression returns the text layout progression for d.func ( Direction) () Progression {if &progression == 0 {return FromTopLeft}return TowardTopLeft}// SetProgression sets the progression, preserving the others bits.func ( *Direction) ( Progression) {if == FromTopLeft {* &= ^progression} else {* |= progression}}// Axis indicates the axis of layout for a piece of text.type Axis boolconst (Horizontal Axis = falseVertical Axis = true)// Progression indicates how text is read within its Axis relative// to the top left corner.type Progression boolconst (// FromTopLeft indicates text in which a reader starts reading// at the top left corner of the text and moves away from it.// DirectionLTR and DirectionTTB are examples of FromTopLeft// Progression.FromTopLeft Progression = false// TowardTopLeft indicates text in which a reader starts reading// at the opposite end of the text's Axis from the top left corner// and moves towards it. DirectionRTL and DirectionBTT are examples// of TowardTopLeft progression.TowardTopLeft Progression = true)// HasVerticalOrientation returns true if the direction has set up// an orientation for vertical text (typically using [SetSideways] or [SetUpright])func ( Direction) () bool { return &verticalOrientationSet != 0 }// IsSideways returns true if the direction is vertical with a 'sideways'// orientation.//// When shaping vertical text, 'sideways' means that the glyphs are rotated// by 90°, clock-wise. This flag should be used by renderers to properly// rotate the glyphs when drawing.func ( Direction) () bool { return .IsVertical() && &verticalSideways != 0 }// SetSideways makes d vertical with 'sideways' or 'upright' orientation, preserving only the// progression.func ( *Direction) ( bool) {* |= axisVertical | verticalOrientationSetif {* |= verticalSideways} else {* &= ^verticalSideways}}// Harfbuzz returns the equivalent direction used by harfbuzz.func ( Direction) () harfbuzz.Direction {switch & (progression | axisVertical) {case DirectionRTL:return harfbuzz.RightToLeftcase DirectionBTT:return harfbuzz.BottomToTopcase DirectionTTB:return harfbuzz.TopToBottomdefault:return harfbuzz.LeftToRight}}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |