Skip to content

Commit 20e96ff

Browse files
authored
Merge pull request #10280 from The-OpenROAD-Project-staging/web-font-atlas
web: anti-aliased font atlas for tile text rendering
2 parents 940703b + cdc1336 commit 20e96ff

22 files changed

Lines changed: 53393 additions & 261 deletions

.github/workflows/github-actions-format-on-push.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ jobs:
2323
run: |
2424
clang-format --version
2525
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
26-
if [[ "${file##*.}" =~ ^(h|C|cc|cp|cpp|c++|CPP|cxx|hh)$ && "${file}" != "src/sta/"* && "${file}" != "src/odb/src/codeGenerator/"* ]]; then
26+
if [[ "${file##*.}" =~ ^(h|C|cc|cp|cpp|c++|CPP|cxx|hh)$ \
27+
&& "${file}" != "src/sta/"* \
28+
&& "${file}" != "src/odb/src/codeGenerator/"* \
29+
&& "${file}" != "third-party/"* ]]; then
2730
clang-format --dry-run --Werror $file
2831
fi
2932
done

src/web/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ cc_library(
113113
"src/clock_tree_report.h",
114114
"src/color.cpp",
115115
"src/color.h",
116+
"src/font_atlas.h",
117+
"src/font_data.cpp",
118+
"src/font_data.h",
119+
"src/glyph_cache.cpp",
120+
"src/glyph_cache.h",
116121
"src/hierarchy_report.cpp",
117122
"src/hierarchy_report.h",
118123
"src/json_builder.h",
@@ -155,6 +160,7 @@ cc_library(
155160
"//src/sta:opensta_lib",
156161
"//src/utl",
157162
"//third-party/lodepng",
163+
"//third-party/stb_truetype",
158164
"@boost.asio",
159165
"@boost.beast",
160166
"@boost.geometry",

src/web/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ target_sources(web
9292
src/hierarchy_report.cpp
9393
src/request_handler.cpp
9494
src/search.cpp
95+
src/font_data.cpp
96+
src/glyph_cache.cpp
9597
src/tile_generator.cpp
9698
src/timing_report.cpp
9799
src/web.cpp
@@ -112,6 +114,7 @@ target_link_libraries(web
112114
gui_heatmap_core
113115
dbSta_lib
114116
lodepng
117+
stb_truetype
115118
utl_lib
116119
)
117120

src/web/fonts/DejaVuSans.ttf

742 KB
Binary file not shown.

src/web/fonts/LICENSE

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
DejaVu Sans
2+
===========
3+
4+
Source: https://dejavu-fonts.github.io/
5+
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved.
6+
Bitstream Vera is a trademark of Bitstream, Inc.
7+
DejaVu changes are in public domain.
8+
9+
Licensed under the Bitstream Vera Fonts License:
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a
12+
copy of the fonts accompanying this license ("Fonts") and associated
13+
documentation files (the "Font Software"), to reproduce and distribute
14+
the Font Software, including without limitation the rights to use, copy,
15+
merge, publish, distribute, and/or sell copies of the Font Software, and
16+
to permit persons to whom the Font Software is furnished to do so,
17+
subject to the following conditions:
18+
19+
The above copyright and trademark notices and this permission notice
20+
shall be included in all copies of one or more of the Font Software
21+
typefaces.
22+
23+
The Font Software may be modified, altered, or added to, and in
24+
particular the designs of glyphs or characters in the Fonts may be
25+
modified and additional glyphs or characters may be added to the Fonts,
26+
only if the fonts are renamed to names not containing either the words
27+
"Bitstream" or the word "Vera".
28+
29+
This License becomes null and void to the extent applicable to Fonts or
30+
Font Software that has been modified and is distributed under the
31+
"Bitstream Vera" names.
32+
33+
The Font Software may be sold as part of a larger software package but
34+
no copy of one or more of the Font Software typefaces may be sold by
35+
itself.
36+
37+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
39+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
40+
COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
41+
BITSTREAM OR THE GNOME FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR
42+
OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL,
43+
OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR
44+
OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT
45+
SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
46+
47+
Except as contained in this notice, the names of Gnome, the Gnome
48+
Foundation, and Bitstream Inc., shall not be used in advertising or
49+
otherwise to promote the sale, use or other dealings in this Font
50+
Software without prior written authorization from the Gnome Foundation
51+
or Bitstream Inc., respectively. For further information, contact:
52+
fonts at gnome dot org.

src/web/src/embed_font.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# Copyright (c) 2025, The OpenROAD Authors
4+
#
5+
# Embed a binary font file as a C++ byte array.
6+
#
7+
# Usage:
8+
# python3 embed_font.py --font fonts/LiberationMono-Regular.ttf -o font_data.cpp
9+
10+
import argparse
11+
12+
13+
def main():
14+
parser = argparse.ArgumentParser(
15+
description="Embed a binary font file as a C++ byte array."
16+
)
17+
parser.add_argument("--font", required=True, help="Path to .ttf font file")
18+
parser.add_argument("--output", "-o", required=True, help="Output .cpp file")
19+
args = parser.parse_args()
20+
21+
with open(args.font, "rb") as f:
22+
data = f.read()
23+
24+
with open(args.output, "w") as f:
25+
f.write("// SPDX-License-Identifier: BSD-3-Clause\n")
26+
f.write("// Copyright (c) 2026, The OpenROAD Authors\n")
27+
f.write("//\n")
28+
f.write("// Auto-generated by embed_font.py — do not edit.\n\n")
29+
f.write('#include "font_data.h"\n\n')
30+
f.write("namespace web {\n\n")
31+
f.write(f"const unsigned int kEmbeddedFontSize = {len(data)};\n\n")
32+
f.write("const unsigned char kEmbeddedFontData[] =\n")
33+
for i in range(0, len(data), 16):
34+
chunk = data[i : i + 16]
35+
escaped = "".join(f"\\{b:03o}" for b in chunk)
36+
f.write(f' "{escaped}"\n')
37+
f.write(";\n\n")
38+
f.write("} // namespace web\n")
39+
40+
41+
if __name__ == "__main__":
42+
main()

src/web/src/font_atlas.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2026, The OpenROAD Authors
3+
//
4+
// Thin shim over GlyphCache so tile_generator.cpp callers stay simple.
5+
6+
#pragma once
7+
8+
#include <string_view>
9+
10+
#include "glyph_cache.h"
11+
12+
namespace web {
13+
14+
inline GlyphCache::FontSize fontAtlasGetFont(int height_px)
15+
{
16+
return glyphCache().getFont(height_px);
17+
}
18+
19+
inline int fontAtlasTextWidth(std::string_view text, int height_px)
20+
{
21+
return glyphCache().textWidth(text, height_px);
22+
}
23+
24+
inline int fontAtlasTextHeight(int height_px)
25+
{
26+
return glyphCache().textHeight(height_px);
27+
}
28+
29+
inline int fontAtlasCellHeight(int height_px)
30+
{
31+
return glyphCache().cellHeight(height_px);
32+
}
33+
34+
inline GlyphCache::GlyphInfo fontAtlasGlyph(int height_px, char ch)
35+
{
36+
return glyphCache().glyph(height_px, ch);
37+
}
38+
39+
inline int fontAtlasKern(int height_px, char ch1, char ch2)
40+
{
41+
return glyphCache().kern(height_px, ch1, ch2);
42+
}
43+
44+
} // namespace web

0 commit comments

Comments
 (0)