Documentation
¶
Overview ¶
Package flow 将顺序内容排版为 OFD 固定版式页面。
本包负责字体度量、UAX #14 断行、分栏分页、表格和导航重排; 对外创作 API 位于 pkg/creator/flow,格式导入器统一经该公开入口使用排版。
Index ¶
- Constants
- func Compose(ctx context.Context, source []Block, opts Options) (*creator.Document, error)
- func ValidateText(text string) error
- type Block
- type Callout
- type CalloutPalette
- type CalloutTheme
- type CellBorders
- type CellStyle
- type Columns
- type Fixed
- type FontFamily
- type Footnote
- type Icon
- type Image
- type Margins
- type NamedStyle
- type Official
- type OfficialColophon
- type OfficialFonts
- type OfficialLetterhead
- type OfficialSignature
- type Options
- type Run
- type Section
- type TOC
- type Table
- type TableBorder
- type TableCell
- type TableColumn
- type TextStyle
- type Theme
Constants ¶
const ( StyleSize = uint32(1 << iota) StyleLineHeight StyleSpaceBefore StyleSpaceAfter StyleFirstLineIndent )
Variables ¶
This section is empty.
Functions ¶
func ValidateText ¶
ValidateText 检查 UTF-8 与控制字符,供公开创作入口与清单入口复用。
Types ¶
type Block ¶
type Block struct {
ID string
Kind string
Text string
Runs []Run
Level int
Marker string
Indent float64
LeftBorderColor *creator.Color
LeadingIcon *Icon
CodeLang string
Style *TextStyle
KeepWithNext bool
KeepTogether bool
PageBreakBefore bool
PageBreakAfter bool
Orphans int
Widows int
Image *Image
Table *Table
Fixed *Fixed
TOC *TOC
Section *Section
Callout *Callout
// contains filtered or unexported fields
}
Block 是顺序创作的内容块,另支持 Markdown 的 quote、code 和 thematic_break。
type Callout ¶
type Callout struct {
Variant, Title string
Text string
Runs []Run
ShowIcon bool
Blocks []Block
Fill, AccentColor *creator.Color
BorderColor *creator.Color
Appearance, Pagination string
RepeatTitle bool
ContinuationSuffix string
// contains filtered or unexported fields
}
Callout 是流式提示容器,容纳段落、列表与代码。
type CalloutPalette ¶
CalloutPalette 是单种提示语义的文档配色。
type CalloutTheme ¶
type CalloutTheme struct {
Neutral, Info, Warning, Danger, Success CalloutPalette
}
CalloutTheme 保存五种提示语义的配色。
type CellBorders ¶
type CellBorders struct{ Top, Right, Bottom, Left *TableBorder }
CellBorders 的空边继承默认边框,Width 为零时隐藏该侧边框。
type CellStyle ¶
type CellStyle struct {
Fill *creator.Color
Padding *Margins
VerticalAlign string
Borders *CellBorders
}
CellStyle 定义单元格的外观,nil 字段继承表格默认设置。
type Fixed ¶
type Fixed struct {
Width, Height float64
Align string
Items []creator.Item
Caption string
Numbered bool
CaptionPrefix string
}
Fixed 是作为整体参与分页的固定区域,内部图元使用左上角为原点的毫米坐标。
type FontFamily ¶
type FontFamily struct{ Regular, Bold, Italic, BoldItalic string }
FontFamily 关联同一字体族的四种实际字体资源。
type Image ¶
type Image struct {
Data []byte
Width float64
Height float64
Align string
Fit string
Caption string
Numbered bool
CaptionPrefix string
}
Image 是图片及图注,尺寸为毫米;未给尺寸时按 96 DPI 推算并限制在版心内。
type Margins ¶
type Margins struct{ Top, Right, Bottom, Left float64 }
Margins 是毫米单位的页边距,指针用于区分继承和显式的零边距。
type Official ¶
type Official struct {
Fonts OfficialFonts
Letterhead *OfficialLetterhead
Signature *OfficialSignature
Colophon *OfficialColophon
PageNumberSize float64
}
type OfficialColophon ¶
type OfficialFonts ¶
type OfficialFonts struct{ Body, Title, Hei, Kai, Song string }
type OfficialLetterhead ¶
type OfficialSignature ¶
type Options ¶
type Options struct {
PageSize creator.PageSize
MarginTop float64
MarginRight float64
MarginBottom float64
MarginLeft float64
Theme Theme
Official *Official
Columns Columns
Styles []NamedStyle
Footnotes []Footnote
FootnoteStyle *TextStyle
Fonts []creator.Font
AllowLogicalFonts bool
CodeFont string
FontFaces map[string]int
FontFamilies []FontFamily
FallbackFonts []string
BoldFont string
ItalicFont string
BoldItalicFont string
PageNumbers bool
Header string
GenerateOutlines bool
ReferencePageNumbers string
// contains filtered or unexported fields
}
Options 控制流式创作的页面、主题与字体。页面长度为毫米。
type Run ¶
type Run struct {
Text string
Font string
Bold bool
Italic bool
Code bool
Strike bool
Color *creator.Color
Link bool
Href string
Target string
PageRef string
CaptionRef string
TitleRef string
Footnote string
// contains filtered or unexported fields
}
Run 是行内文字及其样式和引用;Color 供代码高亮等内部处理使用。
type Section ¶
type Section struct {
PageSize *creator.PageSize
Margins *Margins
Columns *Columns
Header *string
PageNumbers *bool
StartPageNumber *int
PageNumberStyle string
PageNumberPrefix *string
FirstPageHeader *string
HideFirstPageNumber bool
}
Section 覆盖后续页面设置,分页后只以标准物理页、文字和路径输出。
type Table ¶
type Table struct {
// SplitRows 按完整文字行续排普通及 ColSpan 单元格,正文 RowSpan 不支持。
SplitRows bool
Header []string
Rows [][]string
ColumnWidths []float64
// Grid 与 Header/Rows 互斥,合并单元格占据的位置无需额外占位。
Grid [][]TableCell
HeaderRows int
Columns []TableColumn
CellStyle *CellStyle
StripeFill *creator.Color
Caption string
Numbered bool
CaptionPrefix string
RepeatCaption bool
ContinuationSuffix string
}
Table 是简单网格表格,单元格支持自动换行,Header 在续页重复。
type TableBorder ¶
TableBorder 是位于单元格内部的实色边框。
type TableCell ¶
type TableCell struct {
Format string
Text string
Runs []Run
ColSpan int
RowSpan int
Style *TextStyle
Appearance *CellStyle
}
TableCell 是支持局部样式、链接和跨行跨列的单元格。
type TableColumn ¶
TableColumn 配置固定宽或按内容分配的列宽,长度为毫米,Weight 为剩余宽度比例。
type TextStyle ¶
type TextStyle struct {
BasedOn string
Set uint32
Font string
Size float64
LineHeight float64
SpaceBefore float64
SpaceAfter float64
FirstLineIndent float64
Align string
Color *creator.Color
}
TextStyle 是创作主题中的文字样式。字号为磅,段间距与缩进为毫米。
type Theme ¶
type Theme struct {
Body TextStyle
Headings [6]TextStyle
Caption TextStyle
Table TextStyle
BorderColor *creator.Color
HeaderFill *creator.Color
Callouts CalloutTheme
}
Theme 定义正文、各级标题、图注与表格的印刷样式。
func Bootstrap5Theme ¶
func Bootstrap5Theme() Theme
Bootstrap5Theme 按 Bootstrap 5.3 的 H1–H6、正文及 figure-caption 定义印刷样式。 根字号按 16px = 12pt 映射,保留标题 1.2 倍行高与段后 1rem;Medium 使用 Go Bold 近似。 来源:https://github.com/twbs/bootstrap/blob/v5.3.8/scss/_variables.scss
func CarbonTheme ¶
func CarbonTheme() Theme
CarbonTheme 将 Carbon 的静态 heading-06 至 heading-01、body-02、body-compact-01 与 label-01 映射到印刷样式。 按 96px = 72pt 映射字号;Light 使用 Go Regular,Semibold 使用 Go Bold,段间距为印刷预设。 角色来源:https://github.com/carbon-design-system/carbon/blob/main/packages/type/scss/_styles.scss
func Fluent2Theme ¶
func Fluent2Theme() Theme
Fluent2Theme 将 Fluent 2 Web 的字体角色和行高比例用于印刷排版。 按 96px = 72pt 映射字号,段间距为印刷预设;内置字体使用 Go Regular/Bold。 角色来源:https://fluent2.microsoft.design/typography#type-ramp
func GBT9704Theme ¶
func GBT9704Theme(fonts OfficialFonts) Theme
GBT9704Theme 只供 GBT9704Options 组合页面、字体及公文装饰,不独立充当通用 UI 主题。
func Material2Theme ¶
func Material2Theme() Theme
Material2Theme 将 Material 2 Web 的 Headline 1–6、Body 和 Caption 角色用于印刷排版。 按 96px = 72pt 映射字号;Light 使用内置 Go Regular,Medium 使用 Go Bold,段间距与配色为印刷预设。 角色来源:https://github.com/material-components/material-components-web/blob/v14.0.0/packages/mdc-typography/_typography.scss
func Material3Theme ¶
func Material3Theme() Theme
Material3Theme 将 Material 3 Web 的 Headline、Title 和 Body 角色用于印刷排版。 按 96px = 72pt 映射字号,段间距为印刷预设;Medium 字重使用内置 Go Bold 字体面。 角色来源:https://github.com/material-components/material-web/blob/main/tokens/versions/v0_192/_md-sys-typescale.scss
func MaterialTheme ¶
func MaterialTheme() Theme
MaterialTheme 返回适合 A4 报告的主题,借鉴 Material 的字号层级与间距节律。 这里的磅值是印刷预设,不是 dp/sp 到磅的等价换算。
Source Files
¶
- align.go
- balance.go
- block.go
- border.go
- callout.go
- callout_appearance.go
- callout_icon.go
- callout_place.go
- callout_theme.go
- caption.go
- catalog.go
- code.go
- code_wrap.go
- column.go
- compose.go
- doc.go
- engine.go
- fixed.go
- font.go
- footnote.go
- geometry.go
- highlight.go
- icon.go
- image.go
- keep.go
- measure.go
- model.go
- navigation.go
- official.go
- options.go
- outline.go
- pagination.go
- paint.go
- paragraph.go
- recipient.go
- run.go
- section.go
- segment.go
- style.go
- table.go
- table_markdown.go
- table_split.go
- table_style.go
- table_width.go
- text.go
- theme.go