Skip to content

Commit c27f1ab

Browse files
committed
feat(grub-theme): 优化并新增Deepin grub主题支持
- 新增 adjustThemeNormalV25 处理函数,替代旧版本普通主题调整逻辑 - 重构调整启动菜单逻辑,简化 adjustBootMenu 函数,支持不同分辨率下的配置 - 在 Theme 结构体中添加 FindComponentByType 方法,便于根据类型查找组件 - 引入并使用 deepin-v20 主题数据,重命名相关资源文件路径 - 更新 deepin 主题的 theme.txt.tpl 模板,提高启动菜单和标签文字的配置灵活性 - 调整主题背景图片处理逻辑,支持保存背景及主题内背景图 - 测试代码中调用调整普通主题的函数改为新版本接口调用 - 优化字体和界面元素的样式及位置,提升视觉效果和一致性 Bug: PMS-277733
1 parent a712e5d commit c27f1ab

50 files changed

Lines changed: 249 additions & 124 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

adjust-grub-theme/adjust_grub_theme_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (s *su) TestAdjustThemeNormal() {
201201
defer func() {
202202
_ = os.RemoveAll(optThemeOutputDir)
203203
}()
204-
err = adjustThemeNormal()
204+
err = adjustThemeNormalV20()
205205
assert.Equal(s.T(), nil, err)
206206

207207
}

adjust-grub-theme/main.go

Lines changed: 102 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,13 @@ func adjustTheme() {
306306
if optFallbackOnly {
307307
return
308308
}
309-
err = adjustThemeNormal()
309+
err = adjustThemeNormalV25()
310310
if err != nil {
311311
logger.Fatal(err)
312312
}
313313
}
314314

315-
func adjustThemeNormal() error {
315+
func adjustThemeNormalV20() error {
316316
themeInputDir := filepath.Join(optThemeInputDir, themeNameNormal)
317317
themeOutputDir := filepath.Join(optThemeOutputDir, themeNameNormal)
318318

@@ -342,8 +342,6 @@ func adjustThemeNormal() error {
342342

343343
for _, comp := range theme.Components {
344344
if comp.Type == tt.ComponentTypeBootMenu {
345-
adjustBootMenu(themeOutputDir, comp, vars)
346-
347345
iconWidth, _ := comp.GetPropInt("icon_width")
348346
iconHeight, _ := comp.GetPropInt("icon_height")
349347
err = adjustResourcesOsLogos(themeInputDir, themeOutputDir, iconWidth, iconHeight)
@@ -409,6 +407,100 @@ func adjustThemeNormal() error {
409407
return err
410408
}
411409

410+
func adjustThemeNormalV25() error {
411+
themeInputDir := filepath.Join(optThemeInputDir, themeNameNormal)
412+
themeOutputDir := filepath.Join(optThemeOutputDir, themeNameNormal)
413+
414+
cleanupThemeOutputDir(themeOutputDir)
415+
err := os.MkdirAll(themeOutputDir, 0755)
416+
if err != nil {
417+
return err
418+
}
419+
copyThemeFiles(themeInputDir, themeOutputDir)
420+
421+
bgImg, themeBgImg, err := loadV25BackgroundImage()
422+
if err != nil {
423+
return err
424+
}
425+
426+
err = saveJpeg(bgImg, filepath.Join(themeOutputDir, "background.jpg"))
427+
if err != nil {
428+
return err
429+
}
430+
if themeBgImg != nil {
431+
err = saveJpeg(themeBgImg, filepath.Join(themeOutputDir, "background_in_theme.jpg"))
432+
if err != nil {
433+
return err
434+
}
435+
} else {
436+
_, err = copyFile(filepath.Join(themeOutputDir, "background.jpg"),
437+
filepath.Join(themeOutputDir, "background_in_theme.jpg"))
438+
if err != nil {
439+
return err
440+
}
441+
}
442+
443+
themeFile := filepath.Join(themeInputDir, "theme.txt.tpl")
444+
theme, err := tt.ParseThemeFile(themeFile)
445+
if err != nil {
446+
return err
447+
}
448+
449+
bootMenu := theme.FindComponentByType(tt.ComponentTypeBootMenu)
450+
if bootMenu != nil {
451+
adjustBootMenu(bootMenu, optScreenWidth, optScreenHeight)
452+
}
453+
454+
for _, comp := range theme.Components {
455+
if comp.Type == tt.ComponentTypeLabel {
456+
adjustLabelText(comp)
457+
}
458+
}
459+
460+
themeOutput := filepath.Join(themeOutputDir, "theme.txt")
461+
themeOutputFh, err := os.Create(themeOutput)
462+
if err != nil {
463+
return err
464+
}
465+
defer func() {
466+
_ = themeOutputFh.Close()
467+
}()
468+
bw := bufio.NewWriter(themeOutputFh)
469+
// write head
470+
_, err = fmt.Fprintf(bw, "#version:%d\n", VERSION)
471+
if err != nil {
472+
return err
473+
}
474+
_, err = fmt.Fprintf(bw, "#lang:%s\n", optLang)
475+
if err != nil {
476+
return err
477+
}
478+
479+
var inputDir string
480+
inputDir, err = filepath.Abs(themeInputDir)
481+
if err != nil {
482+
logger.Warning(err)
483+
inputDir = themeInputDir
484+
}
485+
486+
_, err = fmt.Fprintf(bw, "#themeInputDir:%s\n", inputDir)
487+
if err != nil {
488+
return err
489+
}
490+
491+
_, err = fmt.Fprintln(bw, "#head end")
492+
if err != nil {
493+
return err
494+
}
495+
496+
_, err = theme.WriteTo(bw)
497+
if err != nil {
498+
return err
499+
}
500+
err = bw.Flush()
501+
return err
502+
}
503+
412504
func adjustThemeFallback() error {
413505
themeInputDir := filepath.Join(optThemeInputDir, themeNameFallback)
414506
themeOutputDir := filepath.Join(optThemeOutputDir, themeNameFallback)
@@ -936,52 +1028,13 @@ func adjustBootMenuPixmapStyle(themeOutputDir string, comp *tt.Component, bgImg
9361028
cropSaveStyleBox(img3, prefix, x+menuR)
9371029
}
9381030

939-
func adjustBootMenu(themeOutputDir string, comp *tt.Component, vars map[string]float64) {
940-
vars = copyVars(vars)
941-
face, err := adjustFont(themeOutputDir, comp, "item_font", vars)
942-
if err != nil {
943-
logger.Fatal(err)
944-
}
945-
946-
fontHeight := face.Height()
947-
vars["font_height"] = float64(fontHeight)
948-
949-
itemHeight := adjustProp(comp, "item_height", vars)
950-
itemR := getItemR(itemHeight)
951-
vars["item_r"] = float64(itemR)
952-
menuR := getBootMenuR(itemHeight)
953-
vars["menu_r"] = float64(menuR)
954-
955-
for _, propName := range []string{
956-
"item_spacing",
957-
"item_padding", "icon_width",
958-
"icon_height", "item_icon_space",
959-
"height", "width",
960-
"left", "top",
961-
} {
962-
adjustProp(comp, propName, vars)
963-
}
964-
965-
scrollbarThumbR := getScrollbarThumbR(menuR)
966-
comp.SetProp("scrollbar_width", scrollbarThumbR*2)
967-
968-
bgImg, err := loadBackgroundImage()
969-
if err != nil {
970-
logger.Fatal(err)
971-
}
972-
973-
bgImg, err = adjustBackground(themeOutputDir, bgImg)
974-
if err != nil {
975-
logger.Fatal(err)
1031+
func adjustBootMenu(comp *tt.Component, width, height int) {
1032+
// bootMenuBasePercent 是 boot menu 宽度计算的基础百分比
1033+
if width == 1024 && height == 768 {
1034+
const bootMenuBasePercent = 18
1035+
comp.SetProp("width", tt.RelNum(bootMenuBasePercent*2))
1036+
comp.SetProp("left", tt.RelNum(50-bootMenuBasePercent))
9761037
}
977-
adjustBootMenuPixmapStyle(themeOutputDir, comp, bgImg)
978-
979-
convertPropAbs2Rel(comp, "left", orientationHorizontal)
980-
convertPropAbs2Rel(comp, "top", orientationVertical)
981-
982-
adjustSelectedItemPixmapStyle(itemR)
983-
adjustItemPixmapStyle(itemR)
984-
adjustScrollbarThumbPixmapStyle(scrollbarThumbR)
9851038
}
9861039

9871040
const (

grub_theme/themetxt/theme.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ func (t *Theme) Dump() {
264264
}
265265
}
266266

267+
// FindComponentByType finds the first component by component type
268+
func (t *Theme) FindComponentByType(compType string) *Component {
269+
for _, comp := range t.Components {
270+
if comp.Type == compType {
271+
return comp
272+
}
273+
}
274+
return nil
275+
}
276+
267277
func (t *Theme) WriteTo(w io.Writer) (n int64, err error) {
268278
for _, prop := range t.Props {
269279
var pn int
File renamed without changes.

misc/data/grub-themes/deepin/resources/os-logos/antergos.svg renamed to misc/data/grub-themes/deepin-v20/resources/os-logos/antergos.svg

File renamed without changes.

misc/data/grub-themes/deepin/resources/os-logos/arch.svg renamed to misc/data/grub-themes/deepin-v20/resources/os-logos/arch.svg

File renamed without changes.

misc/data/grub-themes/deepin/resources/os-logos/chakra.svg renamed to misc/data/grub-themes/deepin-v20/resources/os-logos/chakra.svg

File renamed without changes.

misc/data/grub-themes/deepin/resources/os-logos/debian.svg renamed to misc/data/grub-themes/deepin-v20/resources/os-logos/debian.svg

File renamed without changes.

misc/data/grub-themes/deepin/resources/os-logos/deepin.svg renamed to misc/data/grub-themes/deepin-v20/resources/os-logos/deepin.svg

File renamed without changes.

misc/data/grub-themes/deepin/resources/os-logos/elementary.svg renamed to misc/data/grub-themes/deepin-v20/resources/os-logos/elementary.svg

File renamed without changes.

0 commit comments

Comments
 (0)