Documentation
¶
Overview ¶
Package ppttemplate provides PPT template rendering utilities.
Package ppttemplate loads PPT generation templates — JSON specs that pair a master .pptx file (optional) with theme colors/fonts and pre-defined slide layouts. The CUA reads these so most slide content can be placed by KNOWN coordinates instead of VLM-discovered ones: the single biggest speedup for visible PPT generation (a screen_perceive round is ~8s; a coordinate-driven add is instant).
Templates live in a fixed directory (<user-config>/fairpeer/ppt-templates/) so the user just drops JSON files there; the desktop settings page lists them and lets the user pick the active one. No upload UI, no DB — files on disk.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultDir ¶
func DefaultDir() string
DefaultDir returns the templates directory (<user-config>/fairpeer/ppt-templates), creating it and seeding an example template on first use. Returns "" if the user config dir is unavailable.
func SkillTemplatesDir ¶
func SkillTemplatesDir() string
SkillTemplatesDir returns the PPT skill's templates directory if it exists. This allows the settings page to also show templates bundled with the skill.
Lookup order: the embedded-skill release dir (~/.fairpeer/skills/ppt-auto/ templates, where EnsurePPTAutoSkill writes it) first, then the legacy exe- sibling and user-config locations as fallbacks for older installs.
Types ¶
type Layout ¶
type Layout struct {
TitleX, TitleY, TitleW, TitleH float64 // custom marshal; see below
BodyX, BodyY, BodyW, BodyH float64
}
Layout is the coordinate spec for one slide type. Coordinates are NORMALIZED 0-100 on a 960x540 canvas (same space screen_perceive / ppt text use), so the agent reasons "title near the top" not "at 36 points".
func (Layout) MarshalJSON ¶
MarshalJSON flattens Layout into the on-disk shape.
func (*Layout) UnmarshalJSON ¶
UnmarshalJSON accepts the flat on-disk shape.
type PageRole ¶
type PageRole struct {
// Index is the 1-based slide number in the master_file this role refers to.
// e.g. content role on slide 3 of a 4-page cover/toc/content/closing template.
Index int `json:"index"`
// FillRegion gives the normalized 0-100 area (on the 960x540 canvas) where
// new content text should be placed when this page is used. For "content"
// pages that get duplicated + filled, this is where body text lands (relative
// to the page). Omit for pages used as-is (cover/closing with fixed text).
FillRegion *Layout `json:"fill_region,omitempty"`
}
PageRole describes one slide in the master template by its purpose.
type Template ¶
type Template struct {
// ID is the template's unique id. Defaults to the JSON filename stem.
ID string `json:"id"`
// Name is the human label shown in the settings dropdown.
Name string `json:"name"`
// MasterFile is an optional .pptx the deck opens from (inherits its cover,
// theme, fonts). Empty = use a WPS default blank deck. Absolute path.
MasterFile string `json:"master_file,omitempty"`
// Theme holds colors/fonts applied to added text. All optional.
Theme Theme `json:"theme,omitempty"`
// Layouts maps a layout name (cover/content/section/...) to coordinates for
// its elements. The CUA uses these directly instead of perceiving each slide.
Layouts map[string]Layout `json:"layouts,omitempty"`
// DefaultLayout is used when a slide doesn't specify one (e.g. body slides).
DefaultLayout string `json:"default_layout,omitempty"`
// PageRoles describes what each slide in the master_file IS, so the renderer
// can use them correctly: duplicate the "content" page as a background for
// new body slides, keep the "cover"/"toc"/"closing" pages as-is or fill their
// designated regions. Keys are roles (cover/toc/content/closing/...), values
// carry the 1-based slide index in the master + the content-fill region for
// that role (normalized 0-100, like Layouts). When set, renders build body
// slides by COPYING the content page (preserving its background) rather than
// appending blank slides — the correct way to use a designed template.
PageRoles map[string]PageRole `json:"page_roles,omitempty"`
}
Template is one PPT template spec, parsed from a JSON file in the templates dir. The active template drives PPT generation: its master_file (if set) is opened in WPS instead of a blank deck, and its layouts give ready-made coordinates so the CUA clicks/types at known positions.
func LoadActive ¶
LoadActive returns the template with the given id from dir, or nil if the id is empty / not found. Empty id means "no active template" → the CUA falls back to a default blank deck; not finding a configured id is an error so the user knows the setting points at something deleted.
LoadActive supports both .json template specs AND direct .pptx files. If `id` matches a .json file, that spec is loaded. If it matches a .pptx file (by filename stem), a synthetic template is returned with the .pptx as its MasterFile — so users can simply drop a .pptx into the templates dir and select it without writing any JSON.
func LoadDir ¶
LoadDir scans `dir` for *.json templates AND *.pptx files, returning them sorted by name. .json files are parsed as full template specs; .pptx files that don't have a matching .json are returned as lightweight synthetic templates (ID = filename stem, MasterFile = absolute path) so the user can simply drop a .pptx into the directory and use it without writing JSON. A malformed .json file is skipped (not fatal) so one bad template doesn't break the whole list.
type Theme ¶
type Theme struct {
PrimaryColor string `json:"primary_color,omitempty"` // "RRGGBB" hex, no #
AccentColor string `json:"accent_color,omitempty"`
BackgroundColor string `json:"background_color,omitempty"`
FontTitle string `json:"font_title,omitempty"` // e.g. "微软雅黑"
FontBody string `json:"font_body,omitempty"`
FontSizeTitle int `json:"font_size_title,omitempty"`
FontSizeBody int `json:"font_size_body,omitempty"`
}
Theme is the color/font spec applied to text added by the CUA.