Skip to content

[ADD] checks_odoo_module_scss: new scss-font-legacy-format check with autofix - #205

Merged
moylop260 merged 1 commit into
OCA:mainfrom
vauxoo-dev:scss-font-legacy-format-moy
Nov 30, 2026
Merged

moylop260 merged 1 commit into
OCA:mainfrom
vauxoo-dev:scss-font-legacy-format-moy

Conversation

@moylop260

@moylop260 moylop260 commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Adds scss-font-legacy-format: a @font-face that serves its font as .otf, .ttf, .eot or .woff and no .woff2.

Why WOFF2 and not the other formats

Format Container Compression Use
.ttf / .otf the font as the designer made it none desktop apps, not made for the web
.eot / .svg Internet Explorer only / dead none obsolete
.woff wraps a ttf/otf zlib the first web format
.woff2 wraps a ttf/otf Brotli, with a transform of the glyph tables the smallest

Measured on 13 real fonts of Odoo 19.0 (fontTools 4.69.1, brotli 1.2.1): woff2 is 44.7 % to 71.6 % smaller than the ttf/otf (62.8 % in total, 1 699 716 B to 632 892 B) and 12.5 % to 29.7 % smaller than the woff (26.3 % in total). The CFF .otf fonts gain less than the TrueType ones. On the 17 faces of a real theme, 1 579 500 bytes as otf/ttf/woff became 645 840 bytes as woff2, with the same glyphs (the cmap, the glyph order and count, the advances, the GSUB/GPOS features and the vertical metrics were compared one by one).

Every browser still supported reads WOFF2: Chrome 36, Firefox 39, Safari 12 (partial since 10), Edge 14, 97 % of global use (caniuse and MDN). A src that lists woff2 first and a .woff after it is not reported, because the browser downloads only the first one it understands. With the default font-display the text stays invisible while the font downloads, so its size shows in the First and Largest Contentful Paint (GTmetrix: "Enormous network payloads").

wkhtmltopdf does not read WOFF2

The stylesheets of the PDF report bundles (web.report_assets_common, web.report_assets_pdf, snailmail.report_assets_snailmail, read from the assets of the manifest) are not reported and not fixed. Tested with wkhtmltopdf 0.12.6.1 (patched Qt) and reading the fonts embedded in each PDF: a @font-face with only .ttf or only .woff embeds the font; with only .woff2 the PDF falls back to DejaVuSans and the font is lost; with .woff2 first and .ttf after it, the font is embedded. Without this exemption 36 of 47 findings in public repositories (odoo 14-19, OCA) pointed to a PDF font.

How to migrate (also in the message of the check)

pip install fonttools brotli && fonttools ttLib.woff2 compress Font.otf (or woff2_compress Font.otf) writes Font.woff2 next to the file and keeps every glyph, because only the container changes. Then use url("Font.woff2") format("woff2") and delete the old file. Fonts in .eot or .svg are converted from the original .ttf/.otf.

Autofix

It rewrites the url() and its format() when the .woff2 is already next to the old file, keeping the quotes and the line endings. It does not convert the font: that is a binary file that has to be reviewed and committed, so the check reports it and leaves the file alone. It is idempotent.

Scope

This is the first check that reads stylesheets, so it adds the scss checker: the oca-checks-odoo-module hook now also runs on .scss and .css files (types_or and files of .pre-commit-hooks.yaml) and the checker reads the ones declared in the assets of the manifest. A Sass partial that is only reached through an @import, and .sass or .less files, are not read. Comments are blanked before looking for @font-face, keeping the length, so the line numbers are the ones of the file; Sass interpolation (#{...}) inside the face is supported.

Known limitation, left for another pull request: the ** of the assets globs is not expanded recursively by the existing code (glob.glob without recursive=True), so about 40 % of the stylesheets of odoo 19.0 are not read by any check that uses assets.

Tests

Full suite: 140 passed, 7 skipped (15 new unit tests for the checker, plus the fixture with the autofix and the report bundle). Real corpus: 61 public checkouts (odoo 14-19 and OCA, 4 893 manifests): 47 findings in 5 repositories, 0 in the 35 OCA 18.0 repositories. The README sections were added by hand because the generated README changes its indentation with the Python version.

… autofix

A `@font-face` that serves its font as .otf, .ttf, .eot or .woff and no
.woff2 makes every visitor download a bigger file than needed. WOFF2
compresses with Brotli: measured on 13 real fonts of Odoo 19.0 it is
44-72 % smaller than the .ttf/.otf (63 % in total) and 12-30 % smaller
than the .woff (26 % in total). Every browser still supported reads it
(Chrome 36, Firefox 39, Safari 12, Edge 14), so no other format is
needed as a fallback. With the default font-display the text stays
invisible while the font downloads, so its size shows in the paint
metrics (GTmetrix: "Enormous network payloads").

The message explains how to convert the font without touching its
glyphs. The autofix rewrites the url() and its format() when the .woff2
already sits next to the old file, keeping the quotes and the line
endings; it does not convert the font, since that is a binary file that
has to be reviewed.

The stylesheets of the PDF report bundles (`report_assets_*`) are not
reported: wkhtmltopdf renders them with an old QtWebKit that does not
read WOFF2, and a PDF whose @font-face has only a .woff2 falls back to
another font. The bundle is read from the "assets" of the manifest.

This adds the scss checker: the hook now also runs on .scss and .css
files, and reads the ones declared in the "assets" of the manifest.
@moylop260
moylop260 merged commit 727007f into OCA:main Nov 30, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant