Skip to content

Commit dcd60f6

Browse files
committed
feat(fonts): Add an option to include the Roboto fonts
1 parent 2c91df7 commit dcd60f6

File tree

7 files changed

+79
-0
lines changed

7 files changed

+79
-0
lines changed

fonts/MaterialFontLoader.qml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* QML Material - An application framework implementing Material Design.
3+
*
4+
* Copyright (C) 2016 Michael Spencer <[email protected]>
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
12+
import QtQuick 2.0
13+
14+
Item {
15+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-BlackItalic.ttf")}
16+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-Black.ttf")}
17+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-Bold.ttf")}
18+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-BoldItalic.ttf")}
19+
FontLoader {source: Qt.resolvedUrl("roboto/RobotoCondensed-Bold.ttf")}
20+
FontLoader {source: Qt.resolvedUrl("roboto/RobotoCondensed-BoldItalic.ttf")}
21+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-Medium.ttf")}
22+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-MediumItalic.ttf")}
23+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-Regular.ttf")}
24+
FontLoader {source: Qt.resolvedUrl("roboto/RobotoCondensed-Italic.ttf")}
25+
FontLoader {source: Qt.resolvedUrl("roboto/RobotoCondensed-Light.ttf")}
26+
FontLoader {source: Qt.resolvedUrl("roboto/RobotoCondensed-LightItalic.ttf")}
27+
FontLoader {source: Qt.resolvedUrl("roboto/RobotoCondensed-Regular.ttf")}
28+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-Italic.ttf")}
29+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-Light.ttf")}
30+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-LightItalic.ttf")}
31+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-Thin.ttf")}
32+
FontLoader {source: Qt.resolvedUrl("roboto/Roboto-ThinItalic.ttf")}
33+
}

fonts/fonts.qrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE RCC>
2+
<RCC version="1.0">
3+
4+
<qresource prefix="/Material/Fonts">
5+
<file>MaterialFontLoader.qml</file>
6+
<file>qmldir</file>
7+
<file>roboto/Roboto-Black.ttf</file>
8+
<file>roboto/Roboto-BlackItalic.ttf</file>
9+
<file>roboto/Roboto-Bold.ttf</file>
10+
<file>roboto/Roboto-BoldItalic.ttf</file>
11+
<file>roboto/Roboto-Italic.ttf</file>
12+
<file>roboto/Roboto-Light.ttf</file>
13+
<file>roboto/Roboto-LightItalic.ttf</file>
14+
<file>roboto/Roboto-Medium.ttf</file>
15+
<file>roboto/Roboto-MediumItalic.ttf</file>
16+
<file>roboto/Roboto-Regular.ttf</file>
17+
<file>roboto/Roboto-Thin.ttf</file>
18+
<file>roboto/Roboto-ThinItalic.ttf</file>
19+
<file>roboto/RobotoCondensed-Bold.ttf</file>
20+
<file>roboto/RobotoCondensed-BoldItalic.ttf</file>
21+
<file>roboto/RobotoCondensed-Italic.ttf</file>
22+
<file>roboto/RobotoCondensed-Light.ttf</file>
23+
<file>roboto/RobotoCondensed-LightItalic.ttf</file>
24+
<file>roboto/RobotoCondensed-Regular.ttf</file>
25+
</qresource>
26+
27+
</RCC>

fonts/qmldir

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Material.fonts
2+
3+
MaterialFontLoader 0.1 MaterialFontLoader.qml

material.pri

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ RESOURCES += $$PWD/src/material.qrc \
2020
$$PWD/icons/core_icons.qrc
2121

2222
OTHER_FILES = $$PWD/README.md $$PWD/CHANGELOG.md
23+
24+
contains(OPTIONS, roboto) {
25+
RESOURCES += $$PWD/fonts/fonts.qrc
26+
}

scripts/qrc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def create_qrc(dirname, prefix=None):
2727

2828
for filename in file_list:
2929
if (filename.endswith('.js') or filename.endswith('.qml') or
30+
filename.endswith('.otf') or filename.endswith('.ttf') or
3031
filename == 'qmldir'):
3132
contents += '\t<file>' + filename + '</file>\n'
3233

@@ -46,3 +47,4 @@ def create_qrc(dirname, prefix=None):
4647
create_qrc('src/popups', 'Material')
4748
create_qrc('src/styles', 'QtQuick/Controls/Styles/Material')
4849
create_qrc('src/window', 'Material')
50+
create_qrc('fonts', 'Material/Fonts')

src/core/Theme.qml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,13 @@ Object {
113113

114114
return temp.a > 0 && a >= 0.3
115115
}
116+
117+
Component.onCompleted: {
118+
try {
119+
var code = 'import Material.Fonts 0.1; MaterialFontLoader {}'
120+
Qt.createQmlObject(code, theme, "MaterialFontLoader")
121+
} catch (error) {
122+
// Ignore the error; it only means that the fonts were not enabled
123+
}
124+
}
116125
}

src/core/core.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<qresource prefix="/Material">
55
<file>AwesomeIcon.qml</file>
6+
<file>FontAwesome.otf</file>
67
<file>Icon.qml</file>
78
<file>Ink.qml</file>
89
<file>MaterialAnimation.qml</file>

0 commit comments

Comments
 (0)