diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f884fb..8ef2f33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,12 @@ complete; every release is an annotated git tag `vX.Y.Z` (see `tools/release.sh` adding a vehicle, updates, download folder, resumable download, USB stick, writing, installation guide), Preferences window, About window and new-version check. It uses the gettext catalogs of the GTK interface, and the language of the Locale preferences by default. +- Application icon: an original shield with a "PU" monogram, as SVG, HVIF (embedded in the Haiku + executable) and PNG from 16 to 512 px (installed in the hicolor icon theme on Linux), generated + by `tools/make_icons.py`. ### Fixed +- Translations were installed in `//LC_MESSAGES` instead of the locale directory. - Archive extraction failed when the destination path contained a symbolic link (e.g. `/tmp` on Haiku). - `tools/release.sh` produced empty release notes. diff --git a/README.md b/README.md index 57b588b..30c99b2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +

OpenPU logo

+ # OpenPU A free and native client to download updates for Peugeot head units @@ -81,5 +83,8 @@ the Locale preferences. To add a language: interfaces. ## Tools +- `tools/make_icons.py`: generates the application icon (original artwork, MIT like the rest of + the project) from a single description: `data/icons/openpu.svg`, a simplified variant for 16 and + 24 px, `openpu.hvif` for Haiku and PNG files from 16 to 512 px. Standard library only. - `tools/asar_extract.py`: minimal, read-only asar extractor used to study the reference application. Extracted sources stay **outside the repository**. diff --git a/data/icons/openpu-small.svg b/data/icons/openpu-small.svg new file mode 100644 index 0000000..52885fc --- /dev/null +++ b/data/icons/openpu-small.svg @@ -0,0 +1,13 @@ + + OpenPU + + + + + + + + + + + diff --git a/data/icons/openpu.hvif b/data/icons/openpu.hvif new file mode 100644 index 0000000..a3fff9b Binary files /dev/null and b/data/icons/openpu.hvif differ diff --git a/data/icons/openpu.svg b/data/icons/openpu.svg new file mode 100644 index 0000000..dc2ce77 --- /dev/null +++ b/data/icons/openpu.svg @@ -0,0 +1,16 @@ + + OpenPU + + + + + + + + + + + + + + diff --git a/data/icons/png/openpu-128.png b/data/icons/png/openpu-128.png new file mode 100644 index 0000000..dcc44ac Binary files /dev/null and b/data/icons/png/openpu-128.png differ diff --git a/data/icons/png/openpu-16.png b/data/icons/png/openpu-16.png new file mode 100644 index 0000000..5e7c042 Binary files /dev/null and b/data/icons/png/openpu-16.png differ diff --git a/data/icons/png/openpu-24.png b/data/icons/png/openpu-24.png new file mode 100644 index 0000000..d4d3599 Binary files /dev/null and b/data/icons/png/openpu-24.png differ diff --git a/data/icons/png/openpu-256.png b/data/icons/png/openpu-256.png new file mode 100644 index 0000000..d79ae14 Binary files /dev/null and b/data/icons/png/openpu-256.png differ diff --git a/data/icons/png/openpu-32.png b/data/icons/png/openpu-32.png new file mode 100644 index 0000000..0c3ce9a Binary files /dev/null and b/data/icons/png/openpu-32.png differ diff --git a/data/icons/png/openpu-48.png b/data/icons/png/openpu-48.png new file mode 100644 index 0000000..c4ef0ba Binary files /dev/null and b/data/icons/png/openpu-48.png differ diff --git a/data/icons/png/openpu-512.png b/data/icons/png/openpu-512.png new file mode 100644 index 0000000..9c40dcc Binary files /dev/null and b/data/icons/png/openpu-512.png differ diff --git a/data/icons/png/openpu-64.png b/data/icons/png/openpu-64.png new file mode 100644 index 0000000..93f44f6 Binary files /dev/null and b/data/icons/png/openpu-64.png differ diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt index 5fba50b..7e3ef11 100644 --- a/po/CMakeLists.txt +++ b/po/CMakeLists.txt @@ -1,5 +1,6 @@ # Translations (gettext). Source strings are English; add a language by adding .po and # listing it in LINGUAS. +include(GNUInstallDirs) find_package(Gettext) if(NOT GETTEXT_FOUND) message(WARNING "gettext (msgfmt) not found: translations are not built") diff --git a/src/ui-gtk/CMakeLists.txt b/src/ui-gtk/CMakeLists.txt index 9307052..fe3e62d 100644 --- a/src/ui-gtk/CMakeLists.txt +++ b/src/ui-gtk/CMakeLists.txt @@ -9,9 +9,24 @@ add_executable(openpu target_link_libraries(openpu PRIVATE openpu_core PkgConfig::GTKMM openpu_warnings) target_compile_definitions(openpu PRIVATE GETTEXT_PACKAGE="openpu" - OPENPU_LOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}") + OPENPU_LOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}" + OPENPU_BUILD_ICONDIR="${CMAKE_BINARY_DIR}/icons") # gtkmm headers trigger -Wshadow/-Wconversion noise we cannot fix. target_compile_options(openpu PRIVATE -Wno-shadow -Wno-conversion) install(TARGETS openpu RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES io.github.openpu.OpenPU.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) + +# Application icon (data/icons, generated by tools/make_icons.py), installed in the hicolor theme +# and mirrored in the build tree so that an uninstalled binary finds it too. +set(OPENPU_ICON io.github.openpu.OpenPU) +set(OPENPU_ICONS ${PROJECT_SOURCE_DIR}/data/icons) +configure_file(${OPENPU_ICONS}/openpu.svg ${CMAKE_BINARY_DIR}/icons/hicolor/scalable/apps/${OPENPU_ICON}.svg COPYONLY) +install(FILES ${OPENPU_ICONS}/openpu.svg + DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps RENAME ${OPENPU_ICON}.svg) +foreach(size 16 24 32 48 64 128 256 512) + configure_file(${OPENPU_ICONS}/png/openpu-${size}.png + ${CMAKE_BINARY_DIR}/icons/hicolor/${size}x${size}/apps/${OPENPU_ICON}.png COPYONLY) + install(FILES ${OPENPU_ICONS}/png/openpu-${size}.png + DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/${size}x${size}/apps RENAME ${OPENPU_ICON}.png) +endforeach() diff --git a/src/ui-gtk/main_window.cpp b/src/ui-gtk/main_window.cpp index cf01756..20126e5 100644 --- a/src/ui-gtk/main_window.cpp +++ b/src/ui-gtk/main_window.cpp @@ -94,6 +94,11 @@ MainWindow::MainWindow() { set_title("OpenPU"); set_default_size(640, 520); + // Installed icon from the hicolor theme; the build tree has a copy for uninstalled runs. + auto theme = Gtk::IconTheme::get_for_display(get_display()); + if (!theme->has_icon("io.github.openpu.OpenPU")) + theme->add_search_path(OPENPU_BUILD_ICONDIR); + set_icon_name("io.github.openpu.OpenPU"); try { store_.load(); diff --git a/src/ui-haiku/CMakeLists.txt b/src/ui-haiku/CMakeLists.txt index df8fb6f..ad860dd 100644 --- a/src/ui-haiku/CMakeLists.txt +++ b/src/ui-haiku/CMakeLists.txt @@ -14,6 +14,10 @@ target_compile_definitions(OpenPU PRIVATE target_compile_options(OpenPU PRIVATE -Wno-shadow -Wno-conversion) # Application resources: signature, version, flags (Haiku rc + xres). +# The vector icon (data/icons/openpu.hvif, generated by tools/make_icons.py) is embedded as hex. +set(OPENPU_HVIF ${PROJECT_SOURCE_DIR}/data/icons/openpu.hvif) +file(READ ${OPENPU_HVIF} OPENPU_HVIF_HEX HEX) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${OPENPU_HVIF}) configure_file(OpenPU.rdef.in ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rdef @ONLY) find_program(HAIKU_RC rc) find_program(HAIKU_XRES xres) @@ -24,6 +28,8 @@ if(HAIKU_RC AND HAIKU_XRES) DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rdef) add_custom_target(OpenPU_rsrc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc) add_dependencies(OpenPU OpenPU_rsrc) + # Relink (and so re-attach the resources) when only the resources change. + set_target_properties(OpenPU PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc) add_custom_command(TARGET OpenPU POST_BUILD COMMAND ${HAIKU_XRES} -o $ ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc COMMAND ${HAIKU_MIMESET} -f $) diff --git a/src/ui-haiku/OpenPU.rdef.in b/src/ui-haiku/OpenPU.rdef.in index f595d4a..ae23632 100644 --- a/src/ui-haiku/OpenPU.rdef.in +++ b/src/ui-haiku/OpenPU.rdef.in @@ -4,6 +4,8 @@ resource app_signature "application/x-vnd.openpu-OpenPU"; resource app_flags B_SINGLE_LAUNCH; +resource vector_icon $"@OPENPU_HVIF_HEX@"; + resource app_version { major = @PROJECT_VERSION_MAJOR@, middle = @PROJECT_VERSION_MINOR@, diff --git a/tools/make_icons.py b/tools/make_icons.py new file mode 100644 index 0000000..5adf5f5 --- /dev/null +++ b/tools/make_icons.py @@ -0,0 +1,369 @@ +# SPDX-License-Identifier: MIT +"""Generates the OpenPU application icon (original artwork) in every format the project needs. + +One description of the shapes (64x64 grid, the native grid of HVIF) produces: + data/icons/openpu.svg master SVG + data/icons/openpu-small.svg simplified variant for 16 and 24 px + data/icons/openpu.hvif Haiku Vector Icon Format (embedded in the Haiku executable) + data/icons/png/openpu-N.png PNG renderings, N in SIZES + +Standard library only: the PNGs come from a small antialiased rasterizer below, so no SVG tool +is required. Run from the repository root: python3 -I tools/make_icons.py +""" +import math +import os +import struct +import sys +import zlib + +SIZES = (16, 24, 32, 48, 64, 128, 256, 512) +SMALL_SIZES = (16, 24) + +GRADIENT_TOP = (0x25, 0x63, 0xB8) +GRADIENT_BOTTOM = (0x16, 0x3A, 0x6B) +WHITE = (0xFF, 0xFF, 0xFF) +ARROW = (0x8E, 0xC5, 0xFF) +GRADIENT_Y = (4.0, 60.0) # vertical extent of the gradient, in icon units + +# --- geometry ------------------------------------------------------------------------------------ +# A path is a closed list of points (x, y, in_handle, out_handle); a None handle means a straight +# segment on that side. The segment from p[i] to p[i+1] uses p[i].out and p[i+1].in. + + +def pt(x, y, hin=None, hout=None): + return (x, y, hin, hout) + + +def shield(): + return [ + pt(12, 4, hin=(9.8, 4)), + pt(52, 4, hout=(54.2, 4)), + pt(56, 8, hin=(56, 5.8)), + pt(56, 34, hout=(56, 49)), + pt(32, 61, hin=(45, 57), hout=(19, 57)), + pt(8, 34, hin=(8, 49)), + pt(8, 8, hout=(8, 5.8)), + ] + + +def transform(path, fn): + def f(h): + return None if h is None else fn(*h) + + return [(*fn(x, y), f(hin), f(hout)) for x, y, hin, hout in path] + + +def scaled(path, s, cx=32.0, cy=32.5): + return transform(path, lambda x, y: (cx + s * (x - cx), cy + s * (y - cy))) + + +def moved(path, dx, dy): + return transform(path, lambda x, y: (x + dx, y + dy)) + + +def letter_p(): + return [ + pt(16, 15), + pt(24, 15, hout=(27.9, 15)), + pt(30, 22, hin=(30, 18.1), hout=(30, 25.9)), + pt(24, 29, hin=(27.9, 29)), + pt(22, 29), + pt(22, 37), + pt(16, 37), + ] + + +def letter_p_counter(): + return [ + pt(22, 20), + pt(24, 20, hout=(25.1, 20)), + pt(26, 22, hin=(26, 20.9), hout=(26, 23.1)), + pt(24, 24, hin=(25.1, 24)), + pt(22, 24), + ] + + +def letter_u(): + return [ + pt(34, 15), + pt(40, 15), + pt(40, 29, hout=(40, 30.1)), + pt(42, 31, hin=(40.9, 31), hout=(43.1, 31)), + pt(44, 29, hin=(44, 30.1)), + pt(44, 15), + pt(50, 15), + pt(50, 29, hout=(50, 33.4)), + pt(42, 37, hin=(46.4, 37), hout=(37.6, 37)), + pt(34, 29, hin=(34, 33.4)), + ] + + +def arrow(): + return [pt(30, 41), pt(34, 41), pt(34, 47), pt(39, 47), pt(32, 54), pt(25, 47), pt(30, 47)] + + +def layers(small): + """(style, path) pairs, painted in order. Holes are painted over with the background style, + so every path is a simple filled outline (same result in SVG, HVIF and the rasterizer).""" + dy = 4 if small else 0 # without the arrow, the letters move down to the optical centre + letters = [ + ("white", moved(letter_p(), -1, dy)), + ("gradient", moved(letter_p_counter(), -1, dy)), + ("white", moved(letter_u(), -1, dy)), + ] + out = [("gradient", shield())] + if not small: + out += [("white", scaled(shield(), 0.90)), ("gradient", scaled(shield(), 0.86))] + out += letters + if not small: + out.append(("arrow", arrow())) + return out + + +# --- SVG ----------------------------------------------------------------------------------------- + + +def fmt(v): + return ("%.2f" % v).rstrip("0").rstrip(".") + + +def svg_path(path): + x0, y0 = path[0][:2] + d = ["M%s %s" % (fmt(x0), fmt(y0))] + for i in range(len(path)): + a, b = path[i], path[(i + 1) % len(path)] + if a[3] is None and b[2] is None: + if i + 1 < len(path): + d.append("L%s %s" % (fmt(b[0]), fmt(b[1]))) + continue + c1 = a[3] or a[:2] + c2 = b[2] or b[:2] + d.append("C%s %s %s %s %s %s" % (fmt(c1[0]), fmt(c1[1]), fmt(c2[0]), fmt(c2[1]), fmt(b[0]), fmt(b[1]))) + return " ".join(d) + "Z" + + +def hexcolor(c): + return "#%02x%02x%02x" % c + + +def write_svg(file, small): + fills = {"gradient": "url(#bg)", "white": hexcolor(WHITE), "arrow": hexcolor(ARROW)} + lines = [ + '', + " OpenPU", + " ", + ' ' + % (fmt(GRADIENT_Y[0]), fmt(GRADIENT_Y[1])), + ' ' % hexcolor(GRADIENT_TOP), + ' ' % hexcolor(GRADIENT_BOTTOM), + " ", + " ", + ] + for style, path in layers(small): + lines.append(' ' % (fills[style], svg_path(path))) + lines.append("") + with open(file, "w", encoding="utf-8", newline="\n") as f: + f.write("\n".join(lines) + "\n") + + +# --- HVIF ---------------------------------------------------------------------------------------- +# Format of Haiku's FlatIconImporter: "ncif", then styles, paths and shapes, each list prefixed +# with a uint8 count. Coordinates: one byte (value + 32) for integers in -32..95, otherwise two +# bytes, 0x8000 | round((value + 128) * 102). Matrices use 24-bit floats. + +STYLE_SOLID_NO_ALPHA = 3 +STYLE_GRADIENT = 2 +GRADIENT_LINEAR = 0 +GRADIENT_FLAG_TRANSFORM = 1 << 1 +GRADIENT_FLAG_NO_ALPHA = 1 << 2 +PATH_FLAG_CLOSED = 1 << 1 +PATH_FLAG_NO_CURVES = 1 << 3 +SHAPE_TYPE_PATH_SOURCE = 10 + + +def hvif_coord(v): + if abs(v - round(v)) < 1e-9 and -32 <= round(v) <= 95: + return bytes([int(round(v)) + 32]) + n = int(round((v + 128.0) * 102.0)) + if not 0 <= n < 0x8000: + raise ValueError("coordinate out of range: %r" % v) + return bytes([0x80 | (n >> 8), n & 0xFF]) + + +def float24(v): + if v == 0: + return b"\0\0\0" + bits = struct.unpack("> 31 + exponent = ((bits >> 23) & 0xFF) - 127 + 32 + if not 0 <= exponent < 64: + raise ValueError("float out of range: %r" % v) + value = (sign << 23) | (exponent << 17) | ((bits & 0x7FFFFF) >> 6) + return bytes([(value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF]) + + +def hvif_path(path): + curved = any(p[2] is not None or p[3] is not None for p in path) + out = bytearray([PATH_FLAG_CLOSED | (0 if curved else PATH_FLAG_NO_CURVES), len(path)]) + for x, y, hin, hout in path: + hin = hin or (x, y) + hout = hout or (x, y) + values = (x, y, *hin, *hout) if curved else (x, y) + for v in values: + out += hvif_coord(v) + return bytes(out) + + +def write_hvif(file, small): + # Linear gradients run from -64 to 64 on their own x axis: map it to the vertical extent. + half = (GRADIENT_Y[1] - GRADIENT_Y[0]) / 128.0 + mid = (GRADIENT_Y[0] + GRADIENT_Y[1]) / 2.0 + matrix = (0.0, half, -half, 0.0, 32.0, mid) # agg::trans_affine: sx, shy, shx, sy, tx, ty + gradient = bytearray([STYLE_GRADIENT, GRADIENT_LINEAR, GRADIENT_FLAG_TRANSFORM | GRADIENT_FLAG_NO_ALPHA, 2]) + for m in matrix: + gradient += float24(m) + gradient += bytes([0, *GRADIENT_TOP, 255, *GRADIENT_BOTTOM]) + styles = { + "gradient": bytes(gradient), + "white": bytes([STYLE_SOLID_NO_ALPHA, *WHITE]), + "arrow": bytes([STYLE_SOLID_NO_ALPHA, *ARROW]), + } + used = [] + for style, _ in layers(small): + if style not in used: + used.append(style) + data = bytearray(b"ncif") + data.append(len(used)) + for s in used: + data += styles[s] + ls = layers(small) + data.append(len(ls)) + for _, path in ls: + data += hvif_path(path) + data.append(len(ls)) + for i, (style, _) in enumerate(ls): + data += bytes([SHAPE_TYPE_PATH_SOURCE, used.index(style), 1, i, 0]) + with open(file, "wb") as f: + f.write(data) + return len(data) + + +# --- rasterizer and PNG ---------------------------------------------------------------------------- + + +def flatten(path, steps=24): + poly = [] + for i in range(len(path)): + a, b = path[i], path[(i + 1) % len(path)] + poly.append(a[:2]) + if a[3] is None and b[2] is None: + continue + c1, c2 = a[3] or a[:2], b[2] or b[:2] + for k in range(1, steps): + t = k / steps + u = 1 - t + poly.append(( + u ** 3 * a[0] + 3 * u * u * t * c1[0] + 3 * u * t * t * c2[0] + t ** 3 * b[0], + u ** 3 * a[1] + 3 * u * u * t * c1[1] + 3 * u * t * t * c2[1] + t ** 3 * b[1], + )) + return poly + + +def coverage(poly, size, sub=16): + """Antialiased non-zero coverage (0..1) of a polygon given in 64-unit coordinates.""" + scale = size / 64.0 + pts = [(x * scale, y * scale) for x, y in poly] + edges = [] + for i in range(len(pts)): + (x0, y0), (x1, y1) = pts[i], pts[(i + 1) % len(pts)] + if y0 != y1: + edges.append((x0, y0, x1, y1, 1 if y1 > y0 else -1)) + cov = [0.0] * (size * size) + w = 1.0 / sub + for row in range(size): + base = row * size + for s in range(sub): + y = row + (s + 0.5) / sub + crossings = [] + for x0, y0, x1, y1, d in edges: + if (y0 <= y < y1) or (y1 <= y < y0): + crossings.append((x0 + (y - y0) * (x1 - x0) / (y1 - y0), d)) + crossings.sort() + winding = 0 + for i in range(len(crossings) - 1): + winding += crossings[i][1] + if winding == 0: + continue + xa, xb = max(crossings[i][0], 0.0), min(crossings[i + 1][0], float(size)) + if xb <= xa: + continue + ia, ib = int(xa), int(xb) + if ia == ib: + cov[base + ia] += (xb - xa) * w + continue + cov[base + ia] += (ia + 1 - xa) * w + for px in range(ia + 1, min(ib, size)): + cov[base + px] += w + if ib < size: + cov[base + ib] += (xb - ib) * w + return cov + + +def render(size, small): + rgba = [[0.0, 0.0, 0.0, 0.0] for _ in range(size * size)] # premultiplied + for style, path in layers(small): + cov = coverage(flatten(path), size) + for i, c in enumerate(cov): + if c <= 0: + continue + a = min(c, 1.0) + if style == "gradient": + y = ((i // size) + 0.5) * 64.0 / size + t = min(max((y - GRADIENT_Y[0]) / (GRADIENT_Y[1] - GRADIENT_Y[0]), 0.0), 1.0) + color = [GRADIENT_TOP[k] + (GRADIENT_BOTTOM[k] - GRADIENT_TOP[k]) * t for k in range(3)] + else: + color = WHITE if style == "white" else ARROW + p = rgba[i] + for k in range(3): + p[k] = color[k] / 255.0 * a + p[k] * (1 - a) + p[3] = a + p[3] * (1 - a) + return rgba + + +def write_png(file, size, rgba): + raw = bytearray() + for row in range(size): + raw.append(0) + for p in rgba[row * size:(row + 1) * size]: + a = p[3] + if a <= 0: + raw += b"\0\0\0\0" + continue + raw += bytes([min(255, int(round(p[k] / a * 255))) for k in range(3)] + [int(round(a * 255))]) + + def chunk(kind, payload): + body = kind + payload + return struct.pack(">I", len(payload)) + body + struct.pack(">I", zlib.crc32(body) & 0xFFFFFFFF) + + with open(file, "wb") as f: + f.write(b"\x89PNG\r\n\x1a\n") + f.write(chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))) + f.write(chunk(b"IDAT", zlib.compress(bytes(raw), 9))) + f.write(chunk(b"IEND", b"")) + + +def main(): + root = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data", "icons") + os.makedirs(os.path.join(root, "png"), exist_ok=True) + write_svg(os.path.join(root, "openpu.svg"), small=False) + write_svg(os.path.join(root, "openpu-small.svg"), small=True) + n = write_hvif(os.path.join(root, "openpu.hvif"), small=False) + print("openpu.hvif: %d bytes" % n) + sizes = [int(a) for a in sys.argv[1:]] or SIZES + for size in sizes: + write_png(os.path.join(root, "png", "openpu-%d.png" % size), size, render(size, size in SMALL_SIZES)) + print("openpu-%d.png" % size) + + +if __name__ == "__main__": + main()