Merge branch 'master' into features/slider

This commit is contained in:
Uwe Rathmann 2025-02-28 09:32:48 +01:00
commit e3ec499cc3
73 changed files with 1255 additions and 400 deletions

View File

@ -20,19 +20,25 @@ b) Cassowary constraint solving algorithm ( examples )
SPDX-License-Identifier: BSD 3-Clause "New" or "Revised" License
Copyright (c) 2013, Nucleic Development Team
fonts ( only for running the examples ):
fonts ( needed for the Material3/Fluent2 skin )
a) Material3 Icons
Code: https://github.com/google/material-design-icons
SPDX-License-Identifier: Apache License 2.0
b) Fluent2 Icons
b) Roboto Fonts
Code: https://github.com/googlefonts/roboto-classic
SPDX-License-Identifier: SIL Open Font License 1.1
Copyright 2011 The Roboto Project Authors
c) Fluent2 Icons
Code: https://github.com/microsoft/fluentui-system-icons
SPDX-License-Identifier: MIT License
c) Segoe-UI Fonts
d) Segoe-UI Fonts
Code: https://github.com/mrbvrz/segoe-ui-linux
License: https://github.com/mrbvrz/segoe-ui-linux/blob/master/license.txt

View File

@ -703,9 +703,10 @@ void Editor::setupListViewMetrics()
for ( auto state : { A::NoState, Q::Hovered, Q::Pressed } )
setBoxBorderMetrics( Q::Cell | state | Q::Selected, { 3_px, 0, 0, 0 } );
#if 1
// taken from M3 - what are the actual values, TODO ...
setPadding( Q::Cell, { 16_px, 12_px, 16_px, 12_px } );
setPadding( Q::Cell, 4_px );
setStrutSize( Q::Cell, -1, 40_px );
#endif
}
@ -1561,9 +1562,6 @@ void Editor::setupSpinBoxMetrics()
setSymbol( Q::UpIndicator, symbol( "chevron_up" ) );
setSymbol( Q::DownIndicator, symbol( "chevron_down" ) );
setPadding( Q::UpPanel, { 0, 1_px, 0, 0 } );
setPadding( Q::DownPanel, { 0, 0, 0, 1_px } );
#if 0
// QskSpinBox::Pressed is missing yet
setBoxBorderMetrics( Q::Panel | Q::Pressed, { 1_px, 1_px, 1_px, 2_px } );
@ -1880,7 +1878,6 @@ void Editor::setupTextFieldColors(
{
using Q = QskTextField;
using A = QskAspect;
using W = QskFluent2Skin;
const auto& pal = theme.palette;

View File

@ -0,0 +1,26 @@
Definitions ( where possible ) taken from:
- https://www.figma.com/file/NAWMapFlXnoOb86Q2H5GKr/Windows-UI-(Community)
The Figma model uses the "Segoe Fluent Icons" [1]. Unfortunately its license is
too restrictive for being included in the QSkinny project. Fortunately similar
icons are also available from the "Fluent UI System Icons" project [2].
However glyph names/numbers and the corresponding unicode values do not match
and can't be taken 1:1 from the Figma model.
"Fluent UI System Icons" offers different icon packages ( as font ):
- FluentSystemIcons-Light.ttf
- FluentSystemIcons-Regular.ttf
- FluentSystemIcons-Filled.ttf
- FluentSystemIcons-Resizable.ttf
For some reason ( might be a bug in the downloaded version ) the checkmark
glyph offered from the "Regular" font ( pixelsize 12 ) is different
( works better ) to the one from the "Resizable" font.
That's why we decided to use the "Regular" font for now.
[1] https://learn.microsoft.com/en-us/windows/apps/design/style/segoe-fluent-icons-font
[2] https://github.com/microsoft/fluentui-system-icons

View File

@ -1,10 +0,0 @@
SVGs have been taken from https://github.com/microsoft/fluentui-system-icons/tree/main/assets.
Icons are available in different sizes. As SVGs can be scaled we only need
one version of them - chosing the '12'.
As we are replacing the colors of the SVGs using graphic filters we set the
color in the SVGs manually to black ( instead of #212121 ). So they are in
line with icons coming from somewhere else.
Names have been shortened ( ic_fluent_xyz_16_regular.svg -> xyz.svg )

View File

@ -1,3 +0,0 @@
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9.85355 3.14645C10.0488 3.34171 10.0488 3.65829 9.85355 3.85355L5.35355 8.35355C5.15829 8.54882 4.84171 8.54882 4.64645 8.35355L2.64645 6.35355C2.45118 6.15829 2.45118 5.84171 2.64645 5.64645C2.84171 5.45118 3.15829 5.45118 3.35355 5.64645L5 7.29289L9.14645 3.14645C9.34171 2.95118 9.65829 2.95118 9.85355 3.14645Z" fill="black"/>
</svg>

Before

Width:  |  Height:  |  Size: 444 B

View File

@ -1,3 +0,0 @@
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2.14645 4.64645C2.34171 4.45118 2.65829 4.45118 2.85355 4.64645L6 7.79289L9.14645 4.64645C9.34171 4.45118 9.65829 4.45118 9.85355 4.64645C10.0488 4.84171 10.0488 5.15829 9.85355 5.35355L6.35355 8.85355C6.15829 9.04882 5.84171 9.04882 5.64645 8.85355L2.14645 5.35355C1.95118 5.15829 1.95118 4.84171 2.14645 4.64645Z" fill="black"/>
</svg>

Before

Width:  |  Height:  |  Size: 444 B

View File

@ -1,3 +0,0 @@
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2.14645 7.35355C2.34171 7.54882 2.65829 7.54882 2.85355 7.35355L6 4.20711L9.14645 7.35355C9.34171 7.54882 9.65829 7.54882 9.85355 7.35355C10.0488 7.15829 10.0488 6.84171 9.85355 6.64645L6.35355 3.14645C6.15829 2.95118 5.84171 2.95118 5.64645 3.14645L2.14645 6.64645C1.95118 6.84171 1.95118 7.15829 2.14645 7.35355Z" fill="black"/>
</svg>

Before

Width:  |  Height:  |  Size: 444 B

View File

@ -1,15 +0,0 @@
#! /bin/sh
if [ $# -eq 0 ]; then
echo "Usage $0 file ..."
exit 1
fi
for file in $*
do
base=`basename -s .svg $file`
echo "${base}.svg -> qvg/${base}.qvg"
svg2qvg ${base}.svg qvg/${base}.qvg
done
exit $status

View File

@ -0,0 +1,11 @@
#! /bin/sh
function symbol2qvg {
fontfile=FluentSystemIcons-Regular.ttf
glyph2qvg ${fontfile} 12 $1 qvg/$2.qvg
}
symbol2qvg 1724 checkmark
symbol2qvg 1792 chevron_down
symbol2qvg 1816 chevron_up

View File

@ -1338,7 +1338,7 @@ void Editor::setupListView()
using P = QPalette;
// padding for each cell
setPadding( Q::Cell, QskMargins( 4, 0 ) );
setPadding( Q::Cell, QskMargins( 4, 4 ) );
for ( auto state : { A::NoState, Q::Disabled } )
{

View File

@ -1,21 +1,10 @@
<RCC>
<qresource prefix="/m3">
<!-- needed until we have fixed a rendering bug for small icons -->
<file>icons/qvg/check_small.qvg</file>
<file>icons/qvg/combo-box-arrow-closed.qvg</file>
<file>icons/qvg/combo-box-arrow-open.qvg</file>
<file>icons/qvg/segmented-button-check.qvg</file>
<file>icons/qvg/switchbutton-checked.qvg</file>
<file>icons/qvg/switchbutton-unchecked.qvg</file>
<!-- https://github.com/marella/material-design-icons/tree/main/svg/round -->
<file>icons/qvg/add.qvg</file>
<file>icons/qvg/arrow_drop_down.qvg</file>
<file>icons/qvg/arrow_drop_up.qvg</file>
<file>icons/qvg/check.qvg</file>
<file>icons/qvg/close.qvg</file>
<file>icons/qvg/remove.qvg</file>
</qresource>
</RCC>

View File

@ -227,7 +227,6 @@ void Editor::setupCheckBox()
setStrutSize( Q::Box, 18_px, 18_px );
setBoxBorderMetrics( Q::Box, 2_px );
setBoxShape( Q::Box, 2_px );
setPadding( Q::Box, 3_px ); // "icon size"
QskShadowMetrics shadowMetrics( 12_px, 0.0 );
shadowMetrics.setShapeMode( QskShadowMetrics::Ellipse );
@ -240,7 +239,7 @@ void Editor::setupCheckBox()
setGraphicRole( Q::Indicator | Q::Disabled | Q::Checked,
QskMaterial3Skin::GraphicRoleSurface );
const auto checkMark = symbol( "check_small" );
const auto checkMark = symbol( "check" );
for ( auto state : { A::NoState, Q::Disabled } )
{
const auto aspect = Q::Indicator | Q::Checked | state;
@ -337,7 +336,7 @@ void Editor::setupComboBox()
setColor( Q::Text, m_pal.onSurface );
setFontRole( Q::Text, BodyLarge );
setStrutSize( Q::StatusIndicator, 12_px, 12_px );
setStrutSize( Q::StatusIndicator, 24_px, 24_px );
setGraphicRole( Q::StatusIndicator, QskMaterial3Skin::GraphicRoleOnSurface );
setAlignment( Q::StatusIndicator, Qt::AlignRight | Qt::AlignVCenter );
@ -346,14 +345,13 @@ void Editor::setupComboBox()
setBoxBorderColors( Q::Panel | Q::Disabled, m_pal.onSurface38 );
setGraphicRole( Q::Icon, QskMaterial3Skin::GraphicRoleOnSurface38 );
setColor( Q::Text | Q::Disabled, m_pal.onSurface38 );
setGraphicRole( Q::StatusIndicator, QskMaterial3Skin::GraphicRoleOnSurface38 );
setGraphicRole( Q::StatusIndicator | Q::Disabled, QskMaterial3Skin::GraphicRoleOnSurface38 );
setGraphicRole( Q::Icon | Q::Disabled, QskMaterial3Skin::GraphicRoleOnSurface38 );
setSymbol( Q::StatusIndicator, symbol( "combo-box-arrow-closed" ) );
setSymbol( Q::StatusIndicator | Q::PopupOpen, symbol( "combo-box-arrow-open" ) );
setSymbol( Q::StatusIndicator, symbol( "arrow_drop_down" ) );
setSymbol( Q::StatusIndicator | Q::PopupOpen, symbol( "arrow_drop_up" ) );
}
void Editor::setupBox()
@ -1135,8 +1133,8 @@ void Editor::setupSwitchButton()
setStrutSize( Q::Icon, { 16_px, 16_px } );
setPadding( Q::Icon, 6_px );
setSymbol( Q::Icon, symbol( "switchbutton-unchecked" ) );
setSymbol( Q::Icon | Q::Checked, symbol( "switchbutton-checked" ) );
setSymbol( Q::Icon, symbol( "close" ) );
setSymbol( Q::Icon | Q::Checked, symbol( "check" ) );
setGraphicRole( Q::Icon, QskMaterial3Skin::GraphicRoleSurfaceContainerHighest );

View File

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M18 13h-5v5c0 .55-.45 1-1 1s-1-.45-1-1v-5H6c-.55 0-1-.45-1-1s.45-1 1-1h5V6c0-.55.45-1 1-1s1 .45 1 1v5h5c.55 0 1 .45 1 1s-.45 1-1 1z"/></svg>

Before

Width:  |  Height:  |  Size: 232 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="m8.71 11.71 2.59 2.59c.39.39 1.02.39 1.41 0l2.59-2.59c.63-.63.18-1.71-.71-1.71H9.41c-.89 0-1.33 1.08-.7 1.71z"/></svg>

Before

Width:  |  Height:  |  Size: 211 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M8.71 12.29 11.3 9.7a.996.996 0 0 1 1.41 0l2.59 2.59c.63.63.18 1.71-.71 1.71H9.41c-.89 0-1.33-1.08-.7-1.71z"/></svg>

Before

Width:  |  Height:  |  Size: 208 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M9 16.17 5.53 12.7a.996.996 0 1 0-1.41 1.41l4.18 4.18c.39.39 1.02.39 1.41 0L20.29 7.71a.996.996 0 1 0-1.41-1.41L9 16.17z"/></svg>

Before

Width:  |  Height:  |  Size: 221 B

View File

@ -1,4 +0,0 @@
<svg width="12" height="10" viewBox="0 0 12 10" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4 9.4L0 5.4L1.4 4L4 6.6L10.6 0L12 1.4L4 9.4Z" fill="black"/>
</svg>

Before

Width:  |  Height:  |  Size: 175 B

View File

@ -1,4 +0,0 @@
<svg width="8" height="5" viewBox="0 0 8 5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0.25 0.5L4 4.25L7.75 0.5H0.25Z" fill="black"/>
</svg>

Before

Width:  |  Height:  |  Size: 157 B

View File

@ -1,4 +0,0 @@
<svg width="8" height="5" viewBox="0 0 8 5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0.25 0.5L4 4.25L7.75 0.5H0.25Z" transform="rotate(180 4 2.5)" fill="black"/>
</svg>

Before

Width:  |  Height:  |  Size: 187 B

View File

@ -1,15 +0,0 @@
#! /bin/sh
if [ $# -eq 0 ]; then
echo "Usage $0 file ..."
exit 1
fi
for file in $*
do
base=`basename -s .svg $file`
echo "${base}.svg -> qvg/${base}.qvg"
svg2qvg ${base}.svg qvg/${base}.qvg
done
exit $status

Binary file not shown.

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M18 13H6c-.55 0-1-.45-1-1s.45-1 1-1h12c.55 0 1 .45 1 1s-.45 1-1 1z"/></svg>

Before

Width:  |  Height:  |  Size: 167 B

View File

@ -1,4 +0,0 @@
<svg width="14" height="11" viewBox="0 0 14 11" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4.24914 8.12738L1.12164 4.99988L0.0566406 6.05738L4.24914 10.2499L13.2491 1.24988L12.1916 0.192383L4.24914 8.12738Z" fill="black"/>
</svg>

Before

Width:  |  Height:  |  Size: 246 B

View File

@ -1,4 +0,0 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6.0001 10.78L3.2201 8.00002L2.27344 8.94002L6.0001 12.6667L14.0001 4.66668L13.0601 3.72668L6.0001 10.78Z" fill="black"/>
</svg>

Before

Width:  |  Height:  |  Size: 235 B

View File

@ -1,4 +0,0 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12.6666 4.27337L11.7266 3.33337L7.99992 7.06004L4.27325 3.33337L3.33325 4.27337L7.05992 8.00004L3.33325 11.7267L4.27325 12.6667L7.99992 8.94004L11.7266 12.6667L12.6666 11.7267L8.93992 8.00004L12.6666 4.27337Z" fill="black"/>
</svg>

Before

Width:  |  Height:  |  Size: 339 B

View File

@ -0,0 +1,15 @@
#! /bin/sh
function symbol2qvg {
fontfile=MaterialSymbolsOutlined.ttf
glyph2qvg ${fontfile} 24 $1 qvg/$2.qvg
}
symbol2qvg 3067 check
symbol2qvg 3084 close
symbol2qvg 5022 arrow_drop_down
symbol2qvg 5023 arrow_drop_up
symbol2qvg 3082 add
symbol2qvg 3080 remove

View File

@ -14,7 +14,6 @@
#include <QskStackBoxAnimator.h>
#include <QskPanGestureRecognizer.h>
#include <QQuickFramebufferObject>
#include <QGuiApplication>
#include <QQuickWindow>
#include <QtMath>

View File

@ -31,8 +31,8 @@ class GraphicLabel : public QskGraphicLabel
Inverted
};
GraphicLabel( const QskGraphic& graphic, QQuickItem* parent = nullptr )
: QskGraphicLabel( graphic, parent )
GraphicLabel( QQuickItem* parent = nullptr )
: QskGraphicLabel( parent )
{
setMargins( 10 );
setPanel( true );
@ -74,7 +74,7 @@ class GraphicLabel : public QskGraphicLabel
MainWindow::MainWindow()
{
auto label = new GraphicLabel( QskGraphicIO::read( QString( ":/qvg/Tux.qvg" ) ) );
auto label = new GraphicLabel();
auto invertButton = new QskPushButton( "Inverted" );
invertButton->setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed );
@ -98,6 +98,12 @@ MainWindow::MainWindow()
setGraphicRoles( qskSkinManager->skin() );
}
void MainWindow::setGraphic( const QString& path )
{
if ( auto label = findChild< QskGraphicLabel* >() )
label->setGraphic( QskGraphicIO::read( path ) );
}
void MainWindow::setGraphicRoles( QskSkin* skin )
{
// substituting black

View File

@ -15,6 +15,7 @@ class MainWindow : public QskWindow
public:
MainWindow();
void setGraphic( const QString& );
private Q_SLOTS:
void setGraphicRoles( QskSkin* );

View File

@ -27,6 +27,7 @@ int main( int argc, char* argv[] )
focusIndicator->setObjectName( "FocusIndicator" );
MainWindow window;
window.setGraphic( ( argc > 1 ) ? argv[1] : ":/qvg/Tux.qvg" );
window.resize( 600, 400 );
window.addItem( focusIndicator );
window.show();

View File

@ -3,6 +3,7 @@ add_subdirectory(dials)
add_subdirectory(dialogbuttons)
add_subdirectory(fonts)
add_subdirectory(gradients)
add_subdirectory(iconbrowser)
add_subdirectory(invoker)
add_subdirectory(shadows)
add_subdirectory(shapes)

View File

@ -0,0 +1,15 @@
############################################################################
# QSkinny - Copyright (C) The authors
# SPDX-License-Identifier: BSD-3-Clause
############################################################################
set(SOURCES
GlyphListView.h GlyphListView.cpp
main.cpp
)
qt_add_resources(SOURCES
fonts.qrc
)
qsk_add_example(iconbrowser ${SOURCES})

View File

@ -0,0 +1,130 @@
/******************************************************************************
* QSkinny - Copyright (C) The authors
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include "GlyphListView.h"
#include <QskFunctions.h>
#include <QskGraphic.h>
#include <QskFontRole.h>
#include <QFontMetricsF>
#include <QRawFont>
constexpr int glyphSize = 20;
GlyphListView::GlyphListView( QQuickItem* parentItem )
: Inherited( parentItem )
{
}
GlyphListView::GlyphListView( const QString& fontName, QQuickItem* parentItem )
: GlyphListView( parentItem )
{
setFont( QRawFont( fontName, 16 ) );
setFontRoleHint( Text, QskFontRole::Title );
}
void GlyphListView::setFontPath( const QString& fontPath )
{
setFont( QRawFont( fontPath, 16 ) );
}
void GlyphListView::setFont( const QRawFont& font )
{
m_glyphTable.setIconFont( font );
const auto names = m_glyphTable.nameTable();
m_nameTable.clear();
m_nameTable.reserve( names.size() );
m_maxNameWidth = 0;
{
const QFontMetricsF fm( effectiveFont( Text ) );
for ( auto it = names.constBegin(); it != names.constEnd(); ++it )
{
m_nameTable.insert( it.value(), it.key() );
const qreal w = qskHorizontalAdvance( fm, it.key() );
if ( w > m_maxNameWidth )
m_maxNameWidth = w;
}
}
updateScrollableSize();
update();
}
QRawFont GlyphListView::font() const
{
return m_glyphTable.iconFont();
}
int GlyphListView::rowCount() const
{
return m_glyphTable.glyphCount() - 1;
}
int GlyphListView::columnCount() const
{
return 3;
}
qreal GlyphListView::columnWidth( int col ) const
{
switch( col )
{
case 0:
{
const QFontMetricsF fm( effectiveFont( Text ) );
return qskHorizontalAdvance( fm, "999999" );
}
case 1:
{
const auto hint = strutSizeHint( Cell );
const auto padding = paddingHint( Cell );
const qreal w = glyphSize + padding.left() + padding.right();
return qMax( w, hint.width() );
}
case 2:
return m_maxNameWidth;
}
return 0;
}
qreal GlyphListView::rowHeight() const
{
const auto hint = strutSizeHint( Cell );
const auto padding = paddingHint( Cell );
const qreal h = glyphSize + padding.top() + padding.bottom();
return qMax( h, hint.height() );
}
QVariant GlyphListView::valueAt( int row, int col ) const
{
const auto glyphIndex = row + 1;
switch( col )
{
case 0:
return QVariant::fromValue( QString::number( glyphIndex ) );
case 1:
return QVariant::fromValue( m_glyphTable.glyphGraphic( glyphIndex ) );
case 2:
return QVariant::fromValue( m_nameTable.value( glyphIndex ) );
}
return QVariant();
}
#include "moc_GlyphListView.cpp"

View File

@ -0,0 +1,38 @@
/******************************************************************************
* QSkinny - Copyright (C) The authors
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#pragma once
#include <QskListView.h>
#include <QskGlyphTable.h>
#include <QHash>
class GlyphListView : public QskListView
{
Q_OBJECT
using Inherited = QskListView;
public:
GlyphListView( QQuickItem* = nullptr);
GlyphListView( const QString&, QQuickItem* = nullptr);
void setFontPath( const QString& );
void setFont( const QRawFont& );
QRawFont font() const;
int rowCount() const override;
int columnCount() const override;
virtual qreal columnWidth( int col ) const override;
virtual qreal rowHeight() const override;
QVariant valueAt( int row, int col ) const override;
private:
QskGlyphTable m_glyphTable;
QHash< uint, QString > m_nameTable;
int m_maxNameWidth = 0;
};

View File

@ -0,0 +1,11 @@
<RCC>
<qresource prefix="/iconfonts">
<file alias="FluentIcons.ttf">../../designsystems/fluent2/icons/FluentSystemIcons-Regular.ttf</file>
<file alias="FontAwesomeIcons.otf">fonts/Font Awesome 6 Free-Regular-400.otf</file>
<file alias="IcoMoonIcons.ttf">fonts/IcoMoon-Free.ttf</file>
<file alias="MaterialIcons.ttf">../../designsystems/material3/icons/MaterialSymbolsOutlined.ttf</file>
<file alias="OctIcons.ttf">fonts/Octicons.ttf</file>
</qresource>
</RCC>

Binary file not shown.

View File

@ -0,0 +1,16 @@
a) Font Awesome
Code: https://fontawesome.com/
SPDX-License-Identifier: OFL-1.1-RFN
Copyright (c) 2024 Fonticons, Inc.
b) IcoMoon
Code: https://github.com/Keyamoon/IcoMoon-Free
SPDX-License-Identifier: CC-BY-4.0
c) Octicons
Code: https://github.com/primer/octicons
SPDX-License-Identifier: MIT License

Binary file not shown.

View File

@ -0,0 +1,100 @@
/******************************************************************************
* QSkinny - Copyright (C) The authors
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include "GlyphListView.h"
#include <SkinnyShortcut.h>
#include <QskMainView.h>
#include <QskFocusIndicator.h>
#include <QskObjectCounter.h>
#include <QskWindow.h>
#include <QskComboBox.h>
#include <QGuiApplication>
#include <QRawFont>
#include <QDir>
namespace
{
class Header : public QskLinearBox
{
Q_OBJECT
public:
Header( QQuickItem* parent = nullptr )
: QskLinearBox( Qt::Horizontal, parent )
{
setPaddingHint( QskBox::Panel, 5 );
initSizePolicy( QskSizePolicy::Ignored, QskSizePolicy::Fixed );
setPanel( true );
m_comboBox = new QskComboBox( this );
const auto entries = QDir( ":iconfonts" ).entryInfoList();
for ( const auto& entry : entries )
m_comboBox->addOption( QUrl(), entry.absoluteFilePath() );
m_comboBox->setCurrentIndex( 0 );
connect( m_comboBox, &QskComboBox::currentIndexChanged,
this, &Header::comboBoxChanged );
}
QString fontPath() const { return m_comboBox->currentText(); }
Q_SIGNALS:
void fontChanged( const QString& );
private:
void comboBoxChanged() { Q_EMIT fontChanged( fontPath() ); }
QskComboBox* m_comboBox;
};
class MainView : public QskMainView
{
public:
MainView( QQuickItem* parent = nullptr )
: QskMainView( parent )
{
auto listView = new GlyphListView( this );
auto header = new Header( this );
setHeader( header );
setBody( listView );
listView->setFontPath( header->fontPath() );
connect( header, &Header::fontChanged,
listView, &GlyphListView::setFontPath );
}
};
}
int main( int argc, char* argv[] )
{
#ifdef ITEM_STATISTICS
QskObjectCounter counter( true );
#endif
QGuiApplication app( argc, argv );
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
auto mainView = new QskMainView();
mainView->setBody( new GlyphListView( ":/fonts/Octicons.ttf" ) );
QskWindow window;
window.addItem( new MainView() );
window.addItem( new QskFocusIndicator() );
window.resize( 600, 400 );
window.show();
return app.exec();
}
#include "main.moc"

View File

@ -77,6 +77,8 @@ list(APPEND PRIVATE_HEADERS
list(APPEND HEADERS
graphic/QskColorFilter.h
graphic/QskGlyphGraphicProvider.h
graphic/QskGlyphTable.h
graphic/QskGraphic.h
graphic/QskGraphicImageProvider.h
graphic/QskGraphicIO.h
@ -91,6 +93,8 @@ list(APPEND HEADERS
list(APPEND SOURCES
graphic/QskColorFilter.cpp
graphic/QskGlyphGraphicProvider.cpp
graphic/QskGlyphTable.cpp
graphic/QskGraphic.cpp
graphic/QskGraphicImageProvider.cpp
graphic/QskGraphicIO.cpp

View File

@ -1007,6 +1007,10 @@ void QskItem::itemChange( QQuickItem::ItemChange change,
case QQuickItem::ItemRotationHasChanged:
case QQuickItem::ItemAntialiasingHasChanged:
case QQuickItem::ItemDevicePixelRatioHasChanged:
#if QT_VERSION >= QT_VERSION_CHECK( 6, 9, 0 )
case QQuickItem::ItemScaleHasChanged:
case QQuickItem::ItemTransformHasChanged:
#endif
{
break;
}

View File

@ -29,6 +29,25 @@ QRhi* qskRenderingHardwareInterface( const QQuickWindow* window )
return nullptr;
}
bool qskIsOpenGLWindow( const QQuickWindow* window )
{
if ( window == nullptr )
return false;
const auto renderer = window->rendererInterface();
switch( renderer->graphicsApi() )
{
case QSGRendererInterface::OpenGL:
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
case QSGRendererInterface::OpenGLRhi:
#endif
return true;
default:
return false;
}
}
QRectF qskItemRect( const QQuickItem* item )
{
auto d = QQuickItemPrivate::get( item );

View File

@ -27,6 +27,7 @@ template< typename T > class QList;
*/
QSK_EXPORT QRhi* qskRenderingHardwareInterface( const QQuickWindow* );
QSK_EXPORT bool qskIsOpenGLWindow( const QQuickWindow* );
QSK_EXPORT bool qskIsItemInDestructor( const QQuickItem* );
QSK_EXPORT bool qskIsItemComplete( const QQuickItem* );

View File

@ -0,0 +1,84 @@
/******************************************************************************
* QSkinny - Copyright (C) The authors
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include "QskGlyphGraphicProvider.h"
#include "QskGraphic.h"
#include "QskGlyphTable.h"
#include <qrawfont.h>
#include <qpainter.h>
#include <qpainterpath.h>
class QskGlyphGraphicProvider::PrivateData
{
public:
QskGlyphTable glyphTable;
};
QskGlyphGraphicProvider::QskGlyphGraphicProvider( QObject* parent )
: QskGraphicProvider( parent )
, m_data( new PrivateData )
{
}
QskGlyphGraphicProvider::~QskGlyphGraphicProvider()
{
}
void QskGlyphGraphicProvider::setIconFont( const QRawFont& font )
{
m_data->glyphTable.setIconFont( font );
}
QRawFont QskGlyphGraphicProvider::iconFont() const
{
return m_data->glyphTable.iconFont();
}
QskGraphic QskGlyphGraphicProvider::glyphGraphic( uint index ) const
{
return m_data->glyphTable.glyphGraphic( index );
}
const QskGraphic* QskGlyphGraphicProvider::loadGraphic( const QString& key ) const
{
if ( const auto index = glyphIndex( key ) )
{
const auto graphic = glyphGraphic( index );
if ( !graphic.isNull() )
return new QskGraphic( graphic );
}
return nullptr;
}
uint QskGlyphGraphicProvider::glyphIndex( const QString& key ) const
{
const auto& table = m_data->glyphTable;
if ( ( table.glyphCount() > 0 ) && !key.isEmpty() )
{
if ( key.startsWith( '#' ) )
{
bool ok;
const auto glyphIndex = key.toUInt( &ok );
if ( ok )
return glyphIndex;
}
else if ( key.startsWith( "U+" ) )
{
bool ok;
const char32_t code = key.mid( 2 ).toUInt( &ok, 16 );
if ( ok )
return table.codeToIndex( code );
}
else
{
return table.nameToIndex( key );
}
}
return 0;
}

View File

@ -0,0 +1,35 @@
/******************************************************************************
* QSkinny - Copyright (C) The authors
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#ifndef QSK_GLYPH_GRAPHIC_PROVIDER_H
#define QSK_GLYPH_GRAPHIC_PROVIDER_H
#include "QskGraphicProvider.h"
class QRawFont;
class QSK_EXPORT QskGlyphGraphicProvider : public QskGraphicProvider
{
using Inherited = QskGraphicProvider;
public:
QskGlyphGraphicProvider( QObject* parent = nullptr );
~QskGlyphGraphicProvider() override;
void setIconFont( const QRawFont& );
QRawFont iconFont() const;
QskGraphic glyphGraphic( uint glyphIndex ) const;
protected:
const QskGraphic* loadGraphic( const QString& ) const override final;
virtual uint glyphIndex( const QString& ) const;
private:
class PrivateData;
std::unique_ptr< PrivateData > m_data;
};
#endif

View File

@ -0,0 +1,502 @@
/******************************************************************************
* QSkinny - Copyright (C) The authors
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include "QskGlyphTable.h"
#include "QskGraphic.h"
#include "QskInternalMacros.h"
#include <qrawfont.h>
#include <qpainter.h>
#include <qpainterpath.h>
#include <qendian.h>
QSK_QT_PRIVATE_BEGIN
#include <private/qrawfont_p.h>
QSK_QT_PRIVATE_END
typedef QHash< QString, uint > GlyphNameTable;
/*
The "parsers" below do no validation checks as the font has
already been validated by QRawFont
Hope QRawFont will extend its API some day ( the underlying
font libraries do support glyph names ) and we can remove the nasty
code below. see https://bugreports.qt.io/browse/QTBUG-132629
*/
namespace PostTableParser
{
// https://learn.microsoft.com/en-us/typography/opentype/spec/post
static inline QString toString( const uint8_t* s )
{
// Pascal string. Valid characters are: [AZ] [az] [09] '.' '_'
return QString::fromUtf8(
reinterpret_cast< const char* > ( s + 1 ), *s );
}
static GlyphNameTable glyphNames( const QByteArray& blob )
{
GlyphNameTable names;
const auto* glyphData = reinterpret_cast< const uint16_t* >( blob.constData() + 32 );
if ( const auto nglyphs = qFromBigEndian( *glyphData++ ) )
{
QVarLengthArray< const uint8_t* > strings;
strings.reserve( nglyphs );
const auto from = reinterpret_cast< const uint8_t* >( glyphData + nglyphs );
const auto to = reinterpret_cast< const uint8_t* >( blob.data() + blob.size() );
if ( to > from )
{
for ( auto s = from; s < to; s += *s + 1 )
strings += s;
for ( int i = 0; i < nglyphs; i++ )
{
const int idx = qFromBigEndian( glyphData[i] ) - 258;
if ( idx >= 0 && idx < strings.size() )
names.insert( toString( strings[idx] ), i );
}
}
}
return names;
}
}
namespace CFFTableParser
{
// https://adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf
static uint32_t offsetAt( const uint8_t* d, int size )
{
switch (size)
{
case 0:
return 0;
case 1:
return d[0];
case 2:
return ( d[0] << 8 ) | d[1];
case 3:
return ( d[0] << 16 ) | ( d[1] << 8 ) | d[2];
default:
return ( d[0] << 24 ) | ( d[1] << 16 ) | ( d[2] << 8 ) | d[3];
}
}
static int indexDataSize( const uint8_t* d )
{
const int nitems = ( d[0] << 8 ) | d[1];
if ( nitems == 0 )
return 2;
const int size = d[2];
const uint8_t* lx = d + 3 + nitems * size;
return lx + size - 1 + offsetAt( lx, size ) - d;
}
static const uint8_t* indexData( const uint8_t* d )
{
const int nitems = ( d[0] << 8 ) | d[1];
d += 2;
if ( nitems == 0 )
return d;
const int size = d[0];
const uint8_t* _contents = d + ( nitems + 1 ) * size;
return _contents + offsetAt(d + 1, size);
}
static const uint8_t* skipHeader( const uint8_t* d )
{
return d + d[2];
}
static const uint8_t* skipIndex( const uint8_t* d )
{
return d + indexDataSize( d );
}
static QVector< int > stringIds( const uint8_t* data, int nglyphs )
{
const int format = data[0];
QVector< int > _sids;
_sids += 0;
const uint8_t* p = data + 1;
switch( format )
{
case 0:
{
for (; _sids.size() < nglyphs; p += 2)
{
int sid = ( p[0] << 8 ) | p[1];
_sids += sid;
}
break;
}
case 1:
{
for (; _sids.size() < nglyphs; p += 3)
{
const int sid = ( p[0] << 8 ) | p[1];
const int n = p[2];
for ( int i = 0; i <= n; i++ )
_sids += sid + i;
}
break;
}
case 2:
{
for (; _sids.size() < nglyphs; p += 4)
{
const int sid = ( p[0] << 8 ) | p[1];
const int n = ( p[2] << 8 ) | p[3];
for ( int i = 0; i <= n; i++ )
_sids += sid + i;
}
break;
}
}
return _sids;
}
static int dictValue( const uint8_t* d, int op )
{
/*
see https://adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf
We are intersted in the offset ( operator 15 ).
*/
const uint8_t* data = indexData( d );
int value = 0;
Q_FOREVER
{
// operand
const auto valueType = data[0];
if ( valueType == 28 )
{
value = ( data[1] << 8 ) | data[2];
data += 3;
}
else if ( valueType == 29 )
{
value = ( data[1] << 24 ) | ( data[2] << 16 )
| ( data[3] << 8 ) | data[4];
data += 5;
}
else if ( valueType == 30 )
{
/*
Assuming, that an offset is never a double
we skip the operand without reading it
*/
while( ++data )
{
const int b = *data;
if ( ( b & 0x0f ) == 0x0f || ( b & 0xf0 ) == 0xf0 )
break; // 0xf nibble indicating the end
}
data++;
}
else if ( valueType >= 31 && valueType <= 246 )
{
value = data[0] - 139;
data++;
}
else if ( valueType >= 247 && valueType <= 250 )
{
value = ( ( data[0] - 247 ) << 8 ) + data[1] + 108;
data += 2;
}
else if ( valueType >= 251 && valueType <= 254 )
{
value = -( ( data[0] - 251 ) << 8 ) - data[1] - 108;
data += 2;
}
// operator
if ( op == data[0] )
return value;
data += ( data[0] == 12 ) ? 2 : 1;
}
return 0; // default value
}
class StringTable
{
public:
StringTable( const uint8_t* data )
{
const int nitems = ( data[0] << 8 ) | data[1];
if ( nitems == 0 )
{
_contents = data + 2;
_offset = nullptr;
_offsize = 0;
}
else
{
_offsize = data[2];
_offset = data + 3;
_contents = _offset + nitems * _offsize + _offsize - 1;
}
}
inline QString operator[]( int which ) const
{
const auto x = _offset + which * _offsize;
const auto d1 = _contents + offsetAt(x, _offsize);
const auto d2 = _contents + offsetAt(x + _offsize, _offsize);
return QString::fromUtf8(
reinterpret_cast< const char* >( d1 ), d2 - d1 );
}
private:
const uint8_t* _contents = nullptr;
const uint8_t* _offset = nullptr;
int _offsize = -1;
};
static GlyphNameTable glyphNames( const QByteArray& blob, int glyphCount )
{
auto data = reinterpret_cast< const uint8_t* >( blob.constData() );
auto nameIndex = skipHeader( data );
auto dictIndex = skipIndex( nameIndex );
auto stringIndex = skipIndex( dictIndex );
auto charset = data + dictValue( dictIndex, 15 ); // 15: charset offset
const QVector< int > sids = stringIds( charset, glyphCount );
const StringTable table( stringIndex );
GlyphNameTable names;
for ( int i = 0; i < glyphCount; i++ )
{
/*
The first 391 SIDs are reserved for standard strings
( Appendix A ) that are not from the charset table.
*/
const auto idx = sids[i] - 391;
if ( idx >= 0 )
names.insert( table[idx], i );
}
return names;
}
}
static uint qskGlyphCount( const QRawFont& font )
{
/*
we could also read the count from the "maxp" table:
https://learn.microsoft.com/en-us/typography/opentype/spec/maxp
*/
const auto fontEngine = QRawFontPrivate::get( font )->fontEngine;
return fontEngine ? fontEngine->glyphCount() : 0;
}
static qreal qskPixelSize( const QRawFont& font )
{
const auto fontEngine = QRawFontPrivate::get( font )->fontEngine;
return fontEngine ? fontEngine->fontDef.pixelSize : 0.0;
}
static GlyphNameTable qskGlyphNameTable( const QRawFont& font )
{
const auto count = qskGlyphCount( font );
if ( count > 0 )
{
/*
The Compact Font Format ( CFF ) table has been introduced with
the OpenType specification. For not complying fonts the names
might be found in the Post table
*/
auto blob = font.fontTable( "CFF ");
if ( !blob.isEmpty() )
return CFFTableParser::glyphNames( blob, count );
blob = font.fontTable( "post" );
if ( !blob.isEmpty() )
return PostTableParser::glyphNames( blob );
}
return GlyphNameTable();
}
static inline quint32 qskGlyphIndex( const QRawFont& font, char32_t ucs4 )
{
if ( qskGlyphCount( font ) == 0 )
return 0;
const auto idxs = font.glyphIndexesForString(
QString::fromUcs4( &ucs4, 1 ) );
// fingers crossed: icon fonts will map code points to single glyphs only
Q_ASSERT( idxs.size() == 1 );
return idxs.size() == 1 ? idxs[0] : 0;
}
class QskGlyphTable::PrivateData
{
public:
inline const GlyphNameTable& glyphNameTable() const
{
if ( !validNames )
{
auto that = const_cast< PrivateData* >( this );
that->nameTable = qskGlyphNameTable( font );
that->validNames = true;
}
return nameTable;
}
QRawFont font;
GlyphNameTable nameTable;
bool validNames = false;
};
QskGlyphTable::QskGlyphTable()
: m_data( new PrivateData )
{
}
QskGlyphTable::QskGlyphTable( const QRawFont& font )
: QskGlyphTable()
{
m_data->font = font;
}
QskGlyphTable::QskGlyphTable( const QskGlyphTable& other )
: QskGlyphTable()
{
*m_data = *other.m_data;
}
QskGlyphTable::~QskGlyphTable()
{
}
QskGlyphTable& QskGlyphTable::operator=( const QskGlyphTable& other )
{
if ( m_data != other.m_data )
*m_data = *other.m_data;
return *this;
}
void QskGlyphTable::setIconFont( const QRawFont& font )
{
if ( font != m_data->font )
{
m_data->font = font;
m_data->nameTable.clear();
m_data->validNames = false;
}
}
QRawFont QskGlyphTable::iconFont() const
{
return m_data->font;
}
QPainterPath QskGlyphTable::glyphPath( uint glyphIndex ) const
{
QPainterPath path;
/*
Unfortunately QRawFont::pathForGlyph runs into failing checks
when being called from a different thread - f.e the scene graph thread.
So we need to bypass QRawFont and retrieve from its fontEngine.
*/
if ( auto fontEngine = QRawFontPrivate::get( m_data->font )->fontEngine )
{
QFixedPoint position;
quint32 idx = glyphIndex;
fontEngine->addGlyphsToPath( &idx, &position, 1, &path, {} );
}
return path;
}
QskGraphic QskGlyphTable::glyphGraphic( uint glyphIndex ) const
{
QskGraphic graphic;
if ( glyphIndex > 0 && qskGlyphCount( m_data->font ) > 0 )
{
const auto path = glyphPath( glyphIndex );
if ( !path.isEmpty() )
{
// vertical glyph coordinates are in the range [-sz, 0.0]
const auto sz = qskPixelSize( m_data->font );
graphic.setViewBox( QRectF( 0.0, -sz, sz, sz ) );
QPainter painter( &graphic );
painter.setRenderHint( QPainter::Antialiasing, true );
painter.fillPath( path, Qt::black );
}
}
return graphic;
}
uint QskGlyphTable::glyphCount() const
{
return qskGlyphCount( m_data->font );
}
uint QskGlyphTable::codeToIndex( char32_t ucs4 ) const
{
return qskGlyphIndex( m_data->font, ucs4 );
}
uint QskGlyphTable::nameToIndex( const QString& name ) const
{
/*
Names/Codes that do not correspond to any glyph in should
be mapped to glyph index 0.
see https://learn.microsoft.com/en-us/typography/opentype/spec/cmap
*/
return m_data->glyphNameTable().value( name.toLatin1(), 0 );
}
QHash< QString, uint > QskGlyphTable::nameTable() const
{
return m_data->glyphNameTable();
}

View File

@ -0,0 +1,72 @@
/******************************************************************************
* QSkinny - Copyright (C) The authors
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#ifndef QSK_GLYPH_TABLE_H
#define QSK_GLYPH_TABLE_H
#include "QskGlobal.h"
#include <memory>
class QskGraphic;
class QRawFont;
class QString;
class QPainterPath;
class QByteArray;
class QChar;
template< typename Key, typename T > class QHash;
class QSK_EXPORT QskGlyphTable
{
public:
QskGlyphTable();
QskGlyphTable( const QRawFont& );
QskGlyphTable( const QskGlyphTable& );
~QskGlyphTable();
QskGlyphTable& operator=( const QskGlyphTable& );
bool isValid() const;
void setIconFont( const QRawFont& );
QRawFont iconFont() const;
uint glyphCount() const;
QPainterPath glyphPath( uint glyphIndex ) const;
QskGraphic glyphGraphic( uint glyphIndex ) const;
/*
Most icon fonts use code points from the Unicode Private Use Areas (PUA)
( see https://en.wikipedia.org/wiki/Private_Use_Areas ):
- [0x00e000, 0x00f8ff]
- [0x0f0000, 0x0ffffd]
- [0x100000, 0x10fffd]
Note that QChar is 16-bit entity only that does not cover the higher PUA blocks.
*/
uint codeToIndex( char32_t ) const;
/*
True/OpenType fonts often include a table with glyph names, that can be used
instead of the glyph index
*/
uint nameToIndex( const QString& ) const;
QHash< QString, uint > nameTable() const;
private:
class PrivateData;
std::unique_ptr< PrivateData > m_data;
};
inline bool QskGlyphTable::isValid() const
{
return glyphCount() > 0;
}
#endif

View File

@ -907,7 +907,7 @@ void QskGraphic::drawPath( const QPainterPath& path )
if ( painter == nullptr )
return;
m_data->addCommand( QskPainterCommand( path ) );
addCommand( QskPainterCommand( path ) );
m_data->commandTypes |= QskGraphic::VectorData;
if ( !path.isEmpty() )
@ -938,7 +938,7 @@ void QskGraphic::drawPixmap( const QRectF& rect,
if ( painter == nullptr )
return;
m_data->addCommand( QskPainterCommand( rect, pixmap, subRect ) );
addCommand( QskPainterCommand( rect, pixmap, subRect ) );
m_data->commandTypes |= QskGraphic::RasterData;
const QRectF r = painter->transform().mapRect( rect );
@ -953,7 +953,7 @@ void QskGraphic::drawImage( const QRectF& rect, const QImage& image,
if ( painter == nullptr )
return;
m_data->addCommand( QskPainterCommand( rect, image, subRect, flags ) );
addCommand( QskPainterCommand( rect, image, subRect, flags ) );
m_data->commandTypes |= QskGraphic::RasterData;
const QRectF r = painter->transform().mapRect( rect );
@ -964,7 +964,7 @@ void QskGraphic::drawImage( const QRectF& rect, const QImage& image,
void QskGraphic::updateState( const QPaintEngineState& state )
{
m_data->addCommand( QskPainterCommand( state ) );
addCommand( QskPainterCommand( state ) );
if ( state.state() & QPaintEngine::DirtyTransform )
{
@ -981,6 +981,11 @@ void QskGraphic::updateState( const QPaintEngineState& state )
}
}
void QskGraphic::addCommand( const QskPainterCommand& command )
{
m_data->addCommand( command );
}
void QskGraphic::updateBoundingRect( const QRectF& rect )
{
QRectF br = rect;

View File

@ -146,7 +146,9 @@ class QSK_EXPORT QskGraphic : public QPaintDevice
virtual void drawImage( const QRectF&,
const QImage&, const QRectF&, Qt::ImageConversionFlags );
virtual void updateState( const QPaintEngineState& state );
virtual void updateState( const QPaintEngineState& );
virtual void addCommand( const QskPainterCommand& );
private:
void updateBoundingRect( const QRectF& );

View File

@ -5,9 +5,38 @@
#include "QskGraphicTextureFactory.h"
#include "QskTextureRenderer.h"
#include "QskQuick.h"
#include "QskInternalMacros.h"
#include <qquickwindow.h>
QSK_QT_PRIVATE_BEGIN
#include <private/qsgplaintexture_p.h>
QSK_QT_PRIVATE_END
static QSGTexture* qskCreatePaintedTexture( QQuickWindow* window,
const QSize& size, QskTextureRenderer::PaintHelper* helper )
{
using namespace QskTextureRenderer;
if ( qskIsOpenGLWindow( window ) )
{
const auto textureId = createTextureGL( window, size, helper );
auto texture = new QSGPlainTexture;
texture->setHasAlphaChannel( true );
texture->setOwnsTexture( true );
setTextureId( window, textureId, size, texture );
return texture;
}
else
{
return createTextureRaster( window, size, helper );
}
}
QskGraphicTextureFactory::QskGraphicTextureFactory()
{
}
@ -77,7 +106,7 @@ QSGTexture* QskGraphicTextureFactory::createTexture( QQuickWindow* window ) cons
};
PaintHelper helper( m_graphic, m_colorFilter );
return QskTextureRenderer::createPaintedTexture( window, m_size, &helper );
return qskCreatePaintedTexture( window, m_size, &helper );
}
QSize QskGraphicTextureFactory::textureSize() const

View File

@ -7,6 +7,7 @@
#include "QskSGNode.h"
#include "QskTextureRenderer.h"
#include "QskInternalMacros.h"
#include "QskQuick.h"
#include <qsgimagenode.h>
#include <qquickwindow.h>
@ -160,7 +161,7 @@ void QskPaintedNode::updateTexture( QQuickWindow* window,
{
auto imageNode = findImageNode( this );
if ( ( m_renderHint == OpenGL ) && QskTextureRenderer::isOpenGLWindow( window ) )
if ( ( m_renderHint == OpenGL ) && qskIsOpenGLWindow( window ) )
{
const auto textureId = createTextureGL( window, size, nodeData );
@ -232,5 +233,5 @@ quint32 QskPaintedNode::createTextureGL(
};
PaintHelper helper( this, nodeData );
return createPaintedTextureGL( window, size, &helper );
return QskTextureRenderer::createTextureGL( window, size, &helper );
}

View File

@ -30,8 +30,12 @@ static GLuint qskTakeTexture( QOpenGLFramebufferObject& fbo )
/*
See https://bugreports.qt.io/browse/QTBUG-103929
As we create a FBO for each update of a node we can't live
without having this ( ugly ) workaround.
QOpenGLFramebufferObject::takeTexture produces a memory leak
that can't be accepted as we create an FBO each time we update
a texture.
The suggested workarond is to call QOpenGLSharedResourceGuard::invalidateResource()
manually. Unfortunately this is a protected method and we need this nasty hack.
*/
class MyFBO
{
@ -64,25 +68,6 @@ static GLuint qskTakeTexture( QOpenGLFramebufferObject& fbo )
return textureId;
}
bool QskTextureRenderer::isOpenGLWindow( const QQuickWindow* window )
{
if ( window == nullptr )
return false;
const auto renderer = window->rendererInterface();
switch( renderer->graphicsApi() )
{
case QSGRendererInterface::OpenGL:
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
case QSGRendererInterface::OpenGLRhi:
#endif
return true;
default:
return false;
}
}
void QskTextureRenderer::setTextureId( QQuickWindow* window,
quint32 textureId, const QSize& size, QSGTexture* texture )
{
@ -116,8 +101,8 @@ void QskTextureRenderer::setTextureId( QQuickWindow* window,
#endif
}
quint32 QskTextureRenderer::createPaintedTextureGL(
QQuickWindow* window, const QSize& size, QskTextureRenderer::PaintHelper* helper )
quint32 QskTextureRenderer::createTextureGL(
QQuickWindow* window, const QSize& size, PaintHelper* helper )
{
/*
Binding GL_ARRAY_BUFFER/GL_ELEMENT_ARRAY_BUFFER to 0 seems to be enough.
@ -194,8 +179,8 @@ quint32 QskTextureRenderer::createPaintedTextureGL(
return qskTakeTexture( fbo );
}
static QSGTexture* qskCreateTextureRaster( QQuickWindow* window,
const QSize& size, QskTextureRenderer::PaintHelper* helper )
QSGTexture* QskTextureRenderer::createTextureRaster( QQuickWindow* window,
const QSize& size, PaintHelper* helper )
{
const auto ratio = window ? window->effectiveDevicePixelRatio() : 1.0;
@ -216,24 +201,3 @@ static QSGTexture* qskCreateTextureRaster( QQuickWindow* window,
return window->createTextureFromImage( image, QQuickWindow::TextureHasAlphaChannel );
}
QSGTexture* QskTextureRenderer::createPaintedTexture(
QQuickWindow* window, const QSize& size, PaintHelper* helper )
{
if ( isOpenGLWindow( window ) )
{
const auto textureId = createPaintedTextureGL( window, size, helper );
auto texture = new QSGPlainTexture;
texture->setHasAlphaChannel( true );
texture->setOwnsTexture( true );
setTextureId( window, textureId, size, texture );
return texture;
}
else
{
return qskCreateTextureRaster( window, size, helper );
}
}

View File

@ -27,16 +27,11 @@ namespace QskTextureRenderer
Q_DISABLE_COPY( PaintHelper )
};
bool isOpenGLWindow( const QQuickWindow* );
void setTextureId( QQuickWindow*,
quint32 textureId, const QSize&, QSGTexture* );
quint32 createPaintedTextureGL(
QQuickWindow*, const QSize&, QskTextureRenderer::PaintHelper* );
QSK_EXPORT QSGTexture* createPaintedTexture(
QQuickWindow* window, const QSize& size, PaintHelper* helper );
quint32 createTextureGL( QQuickWindow*, const QSize&, PaintHelper* );
QSGTexture* createTextureRaster( QQuickWindow*, const QSize&, PaintHelper* );
}
#endif

View File

@ -21,51 +21,87 @@
#include <QPainterPath>
#include <QDebug>
enum Options
{
ViewBox = 1 << 0,
Antialiasing = 1 << 1
};
static void usage( const char* appName )
{
qWarning() << "usage: " << appName << "<fontfile> <glyphindex> <qvgfile>";
qWarning() << "usage: " << appName << "<fontfile> <pixelsize> <glyphindex> <qvgfile>";
}
static QPainterPath glyphPath( const QRawFont& font,
const qreal pixelSize, const uint glyphIndex )
{
auto path = font.pathForGlyph( glyphIndex );
path = path.simplified();
path = path.translated( 0.0, pixelSize );
return path;
}
static QskGraphic icon( const QPainterPath& path,
const qreal pixelSize, const int options )
{
QskGraphic graphic;
if ( options & ViewBox )
graphic.setViewBox( QRectF( 0.0, 0.0, pixelSize, pixelSize ) );
QPainter painter( &graphic );
if ( options & Antialiasing )
painter.setRenderHint( QPainter::Antialiasing, true );
painter.fillPath( path, Qt::black );
return graphic;
}
int main( int argc, char* argv[] )
{
if ( argc != 4 )
QGuiApplication app( argc, argv );
if ( argc != 5 )
{
usage( argv[0] );
return -1;
}
QGuiApplication app( argc, argv );
bool ok;
QRawFont font( QString( argv[1] ), 16 );
const auto pixelSize = QString( argv[2] ).toDouble( &ok );
if ( !ok || ( pixelSize <= 0 ) )
{
qWarning() << "invalid pixel size:" << argv[2];
return -3;
}
const auto glyphIndex = QString( argv[3] ).toUInt( &ok );
if ( !ok )
{
qWarning() << "invalid glyph index:" << argv[3];
return -3;
}
QRawFont font( QString( argv[1] ), pixelSize );
if ( !font.isValid() )
{
qWarning() << "invalid font name:" << argv[1];
return -2;
}
bool ok;
const auto glyphIndex = QString( argv[2] ).toUInt( &ok );
if ( !ok )
{
qWarning() << "invalid glyph index:" << argv[2];
return -3;
}
const auto path = font.pathForGlyph( glyphIndex );
const auto path = glyphPath( font, pixelSize, glyphIndex );
if ( path.isEmpty() )
{
qWarning() << "no glyph for index:" << argv[2];
qWarning() << "no glyph for index:" << argv[3];
return -3;
}
QskGraphic graphic;
QPainter painter( &graphic );
painter.setRenderHint( QPainter::Antialiasing, true );
painter.fillPath( path, Qt::black );
QskGraphicIO::write( graphic, argv[3] );
const auto graphic = icon( path, pixelSize, ViewBox | Antialiasing );
QskGraphicIO::write( graphic, argv[4] );
return 0;
}

View File

@ -41,6 +41,28 @@ static QRectF viewBox( QSvgRenderer& renderer )
return hasViewBox ? viewBox : QRectF( 0.0, 0.0, -1.0, -1.0 );
}
class Graphic : public QskGraphic
{
protected:
void addCommand( const QskPainterCommand& cmd ) override
{
#if 0
if ( cmd.type() == QskPainterCommand::State )
{
/*
QSvgRenderer enables QPainter::Antialiasing initially
However this is something we might want to decide,
when replaying the commands.
*/
auto sd = const_cast< QskPainterCommand::StateData* >( cmd.stateData() );
sd->renderHints &= ~QPainter::Antialiasing;
}
#endif
QskGraphic::addCommand( cmd );
}
};
int main( int argc, char* argv[] )
{
if ( argc != 3 )
@ -71,7 +93,7 @@ int main( int argc, char* argv[] )
if ( !renderer.load( QString( argv[1] ) ) )
return -2;
QskGraphic graphic;
Graphic graphic;
graphic.setViewBox( ::viewBox( renderer ) );
QPainter painter( &graphic );