|
1 | | -// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. |
| 1 | +// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd. |
2 | 2 | // |
3 | 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | 4 |
|
@@ -162,11 +162,8 @@ func getFontSize(screenWidth int, screenHeight int) int { |
162 | 162 | return round(y) |
163 | 163 | } |
164 | 164 |
|
165 | | -func getScreenSizeFromGrubParams(grubParamsFilePath string) (w, h int, err error) { |
166 | | - params, err := loadGrubParams(grubParamsFilePath) |
167 | | - if err != nil { |
168 | | - return |
169 | | - } |
| 165 | +func getScreenSizeFromGrubParams(grubParamsFilePaths []string) (w, h int, err error) { |
| 166 | + params := loadGrubParams(grubParamsFilePaths) |
170 | 167 |
|
171 | 168 | w, h, err = parseResolution(getGfxMode(params)) |
172 | 169 | if err != nil { |
@@ -306,13 +303,13 @@ func adjustTheme() { |
306 | 303 | if optFallbackOnly { |
307 | 304 | return |
308 | 305 | } |
309 | | - err = adjustThemeNormal() |
| 306 | + err = adjustThemeNormalV25() |
310 | 307 | if err != nil { |
311 | 308 | logger.Fatal(err) |
312 | 309 | } |
313 | 310 | } |
314 | 311 |
|
315 | | -func adjustThemeNormal() error { |
| 312 | +func adjustThemeNormalV20() error { |
316 | 313 | themeInputDir := filepath.Join(optThemeInputDir, themeNameNormal) |
317 | 314 | themeOutputDir := filepath.Join(optThemeOutputDir, themeNameNormal) |
318 | 315 |
|
@@ -409,6 +406,100 @@ func adjustThemeNormal() error { |
409 | 406 | return err |
410 | 407 | } |
411 | 408 |
|
| 409 | +func adjustThemeNormalV25() error { |
| 410 | + themeInputDir := filepath.Join(optThemeInputDir, themeNameNormal) |
| 411 | + themeOutputDir := filepath.Join(optThemeOutputDir, themeNameNormal) |
| 412 | + |
| 413 | + cleanupThemeOutputDir(themeOutputDir) |
| 414 | + err := os.MkdirAll(themeOutputDir, 0755) |
| 415 | + if err != nil { |
| 416 | + return err |
| 417 | + } |
| 418 | + copyThemeFiles(themeInputDir, themeOutputDir) |
| 419 | + |
| 420 | + bgImg, themeBgImg, err := loadV25BackgroundImage() |
| 421 | + if err != nil { |
| 422 | + return err |
| 423 | + } |
| 424 | + |
| 425 | + err = saveJpeg(bgImg, filepath.Join(themeOutputDir, "background.jpg")) |
| 426 | + if err != nil { |
| 427 | + return err |
| 428 | + } |
| 429 | + if themeBgImg != nil { |
| 430 | + err = saveJpeg(themeBgImg, filepath.Join(themeOutputDir, "background_in_theme.jpg")) |
| 431 | + if err != nil { |
| 432 | + return err |
| 433 | + } |
| 434 | + } else { |
| 435 | + _, err = copyFile(filepath.Join(themeOutputDir, "background.jpg"), |
| 436 | + filepath.Join(themeOutputDir, "background_in_theme.jpg")) |
| 437 | + if err != nil { |
| 438 | + return err |
| 439 | + } |
| 440 | + } |
| 441 | + |
| 442 | + themeFile := filepath.Join(themeInputDir, "theme.txt.tpl") |
| 443 | + theme, err := tt.ParseThemeFile(themeFile) |
| 444 | + if err != nil { |
| 445 | + return err |
| 446 | + } |
| 447 | + |
| 448 | + bootMenu := theme.FindComponentByType(tt.ComponentTypeBootMenu) |
| 449 | + if bootMenu != nil { |
| 450 | + adjustBootMenuV25(bootMenu, optScreenWidth, optScreenHeight) |
| 451 | + } |
| 452 | + |
| 453 | + for _, comp := range theme.Components { |
| 454 | + if comp.Type == tt.ComponentTypeLabel { |
| 455 | + adjustLabelText(comp) |
| 456 | + } |
| 457 | + } |
| 458 | + |
| 459 | + themeOutput := filepath.Join(themeOutputDir, "theme.txt") |
| 460 | + themeOutputFh, err := os.Create(themeOutput) |
| 461 | + if err != nil { |
| 462 | + return err |
| 463 | + } |
| 464 | + defer func() { |
| 465 | + _ = themeOutputFh.Close() |
| 466 | + }() |
| 467 | + bw := bufio.NewWriter(themeOutputFh) |
| 468 | + // write head |
| 469 | + _, err = fmt.Fprintf(bw, "#version:%d\n", VERSION) |
| 470 | + if err != nil { |
| 471 | + return err |
| 472 | + } |
| 473 | + _, err = fmt.Fprintf(bw, "#lang:%s\n", optLang) |
| 474 | + if err != nil { |
| 475 | + return err |
| 476 | + } |
| 477 | + |
| 478 | + var inputDir string |
| 479 | + inputDir, err = filepath.Abs(themeInputDir) |
| 480 | + if err != nil { |
| 481 | + logger.Warning(err) |
| 482 | + inputDir = themeInputDir |
| 483 | + } |
| 484 | + |
| 485 | + _, err = fmt.Fprintf(bw, "#themeInputDir:%s\n", inputDir) |
| 486 | + if err != nil { |
| 487 | + return err |
| 488 | + } |
| 489 | + |
| 490 | + _, err = fmt.Fprintln(bw, "#head end") |
| 491 | + if err != nil { |
| 492 | + return err |
| 493 | + } |
| 494 | + |
| 495 | + _, err = theme.WriteTo(bw) |
| 496 | + if err != nil { |
| 497 | + return err |
| 498 | + } |
| 499 | + err = bw.Flush() |
| 500 | + return err |
| 501 | +} |
| 502 | + |
412 | 503 | func adjustThemeFallback() error { |
413 | 504 | themeInputDir := filepath.Join(optThemeInputDir, themeNameFallback) |
414 | 505 | themeOutputDir := filepath.Join(optThemeOutputDir, themeNameFallback) |
@@ -585,7 +676,10 @@ func main() { |
585 | 676 |
|
586 | 677 | if optScreenWidth == 0 || optScreenHeight == 0 { |
587 | 678 | var err error |
588 | | - optScreenWidth, optScreenHeight, err = getScreenSizeFromGrubParams(grubParamsFile) |
| 679 | + optScreenWidth, optScreenHeight, err = getScreenSizeFromGrubParams([]string{ |
| 680 | + grubParamsFile, |
| 681 | + ddeGrubParamsFile, |
| 682 | + }) |
589 | 683 | if err != nil { |
590 | 684 | logger.Debug(err) |
591 | 685 | optScreenWidth = 1024 |
@@ -984,6 +1078,16 @@ func adjustBootMenu(themeOutputDir string, comp *tt.Component, vars map[string]f |
984 | 1078 | adjustScrollbarThumbPixmapStyle(scrollbarThumbR) |
985 | 1079 | } |
986 | 1080 |
|
| 1081 | +func adjustBootMenuV25(comp *tt.Component, width, height int) { |
| 1082 | + if width == 1024 && height == 768 { |
| 1083 | + // halfWidthPercent represents half of the boot menu width percentage. |
| 1084 | + // The boot menu is centered, so width = halfWidthPercent * 2, left = 50% - halfWidthPercent, |
| 1085 | + halfWidthPercent := 22 |
| 1086 | + comp.SetProp("width", tt.RelNum(halfWidthPercent*2)) |
| 1087 | + comp.SetProp("left", tt.RelNum(50-halfWidthPercent)) |
| 1088 | + } |
| 1089 | +} |
| 1090 | + |
987 | 1091 | const ( |
988 | 1092 | orientationHorizontal = 0 |
989 | 1093 | orientationVertical = 1 |
|
0 commit comments