Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deduplicated font type #439

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions lib/fontType.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
{
lib,
...
}: let
inherit (lib) mkOption types;
qfont = import ./qfont.nix { inherit lib; };

styleStrategyType = types.submodule {
options = with qfont.styleStrategy; {
prefer = mkOption {
type = prefer;
default = "default";
description = ''
Which type of font is preferred by the font when finding an appropriate default family.

`default`, `bitmap`, `device`, `outline`, `forceOutline` correspond to the
`PreferDefault`, `PreferBitmap`, `PreferDevice`, `PreferOutline`, `ForceOutline` enum flags
respectively.
'';
};
matchingPrefer = mkOption {
type = matchingPrefer;
default = "default";
description = ''
Whether the font matching process prefers exact matches, or best quality matches.

`default` corresponds to not setting any enum flag, and `exact` and `quality`
correspond to `PreferMatch` and `PreferQuality` enum flags respectively.
'';
};
antialiasing = mkOption {
type = antialiasing;
default = "default";
description = ''
Whether antialiasing is preferred for this font.

`default` corresponds to not setting any enum flag, and `prefer` and `disable`
correspond to `PreferAntialias` and `NoAntialias` enum flags respectively.
'';
};
noSubpixelAntialias = mkOption {
type = types.bool;
default = false;
description = ''
If set to `true`, this font will try to avoid subpixel antialiasing.

Corresponds to the `NoSubpixelAntialias` enum flag.
'';
};
noFontMerging = mkOption {
type = types.bool;
default = false;
description = ''
If set to `true`, this font will not try to find a substitute font when encountering missing glyphs.

Corresponds to the `NoFontMerging` enum flag.
'';
};
preferNoShaping = mkOption {
type = types.bool;
default = false;
description = ''
If set to true, this font will not try to apply shaping rules that may be required for some scripts
(e.g. Indic scripts), increasing performance if these rules are not required.

Corresponds to the `PreferNoShaping` enum flag.
'';
};
};
};
in types.submodule {
options = {
family = mkOption {
type = types.str;
description = "The font family of this font.";
example = "Noto Sans";
};
pointSize = mkOption {
type = types.nullOr types.numbers.positive;
default = null;
description = ''
The point size of this font.

Could be a decimal, but usually an integer. Mutually exclusive with pixel size.
'';
};
pixelSize = mkOption {
type = types.nullOr types.ints.u16;
default = null;
description = ''
The pixel size of this font.

Mutually exclusive with point size.
'';
};
styleHint = mkOption {
type = qfont.styleHint;
default = "anyStyle";
description = ''
The style hint of this font.

See https://doc.qt.io/qt-6/qfont.html#StyleHint-enum for more.
'';
};
weight = mkOption {
type = types.either (types.ints.between 1 1000) qfont.weight;
default = "normal";
description = ''
The weight of the font, either as a number between 1 to 1000 or as a pre-defined weight string.

See https://doc.qt.io/qt-6/qfont.html#Weight-enum for more.
'';
};
style = mkOption {
type = qfont.style;
default = "normal";
description = "The style of the font.";
};
underline = mkOption {
type = types.bool;
default = false;
description = "Whether the font is underlined.";
};
strikeOut = mkOption {
type = types.bool;
default = false;
description = "Whether the font is struck out.";
};
fixedPitch = mkOption {
type = types.bool;
default = false;
description = "Whether the font has a fixed pitch.";
};
capitalization = mkOption {
type = qfont.capitalization;
default = "mixedCase";
description = ''
The capitalization settings for this font.

See https://doc.qt.io/qt-6/qfont.html#Capitalization-enum for more.
'';
};
letterSpacingType = mkOption {
type = qfont.spacingType;
default = "percentage";
description = ''
Whether to use percentage or absolute spacing for this font.

See https://doc.qt.io/qt-6/qfont.html#SpacingType-enum for more.
'';
};
letterSpacing = mkOption {
type = types.number;
default = 0;
description = ''
The amount of letter spacing for this font.

Could be a percentage or an absolute spacing change (positive increases spacing, negative decreases spacing),
based on the selected `letterSpacingType`.
'';
};
wordSpacing = mkOption {
type = types.number;
default = 0;
description = ''
The amount of word spacing for this font, in pixels.

Positive values increase spacing while negative ones decrease spacing.
'';
};
stretch = mkOption {
type = types.either (types.ints.between 1 4000) qfont.stretch;
default = "anyStretch";
description = ''
The stretch factor for this font, as an integral percentage (i.e. 150 means a 150% stretch),
or as a pre-defined stretch factor string.
'';
};
styleStrategy = mkOption {
type = styleStrategyType;
default = { };
description = ''
The strategy for matching similar fonts to this font.

See https://doc.qt.io/qt-6/qfont.html#StyleStrategy-enum for more.
'';
};
styleName = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
The style name of this font, overriding the `style` and `weight` parameters when set.
Used for special fonts that have styles beyond traditional settings.
'';
};
};
}
Loading
Loading