[Libreoffice-commits] core.git: include/vcl vcl/inc vcl/source
Tomaž Vajngerl
tomaz.vajngerl at collabora.co.uk
Sun Jun 24 13:34:05 UTC 2018
include/vcl/font/Feature.hxx | 4 -
vcl/inc/font/OpenTypeFeatureDefinitonList.hxx | 3
vcl/inc/font/OpenTypeFeatureStrings.hrc | 33 --------
vcl/source/font/Feature.cxx | 15 +++-
vcl/source/font/OpenTypeFeatureDefinitonList.cxx | 85 +++++++++++++++--------
5 files changed, 77 insertions(+), 63 deletions(-)
New commits:
commit a7af4bbbc0793fb78aea6a89f8fb6dc052710a11
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Sat Jun 23 16:01:19 2018 +0200
vcl: treat description of cv** & ss** font features specially
To avoid adding descriptions for each of font features cv** and
ss**, where ** is a number between 00-99, process them separately
and just use one description for each. This simplifies translation
as we don't need to add 99 copy-paste translations but add a bit
more complexity when looking up the descriptions.
Change-Id: Ia6e9554af20355c90c73afeec33fd18c694865b9
Reviewed-on: https://gerrit.libreoffice.org/56317
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/font/Feature.hxx b/include/vcl/font/Feature.hxx
index 0ab375e1a76c..9b0d29db3190 100644
--- a/include/vcl/font/Feature.hxx
+++ b/include/vcl/font/Feature.hxx
@@ -56,6 +56,7 @@ private:
sal_uInt32 m_nCode;
OUString m_sDescription;
const char* m_pDescriptionID;
+ OUString m_sNumericPart;
FeatureParameterType m_eType;
// the index of the parameter defines the enum value, string is the description
std::vector<FeatureParameter> m_aEnumParameters;
@@ -66,7 +67,8 @@ public:
FeatureParameterType eType = FeatureParameterType::BOOL,
std::vector<FeatureParameter> const& rEnumParameters
= std::vector<FeatureParameter>{});
- FeatureDefinition(sal_uInt32 nCode, const char* pDescriptionID);
+ FeatureDefinition(sal_uInt32 nCode, const char* pDescriptionID,
+ OUString const& rNumericPart = OUString());
FeatureDefinition(sal_uInt32 nCode, const char* pDescriptionID,
std::vector<FeatureParameter> aEnumParameters);
diff --git a/vcl/inc/font/OpenTypeFeatureDefinitonList.hxx b/vcl/inc/font/OpenTypeFeatureDefinitonList.hxx
index b5abb2708f4f..740043bbff56 100644
--- a/vcl/inc/font/OpenTypeFeatureDefinitonList.hxx
+++ b/vcl/inc/font/OpenTypeFeatureDefinitonList.hxx
@@ -30,6 +30,9 @@ private:
void init();
+ static bool isSpecialFeatureCode(sal_uInt32 nFeatureCode);
+ FeatureDefinition handleSpecialFeatureCode(sal_uInt32 nFeatureCode);
+
public:
OpenTypeFeatureDefinitonListPrivate();
FeatureDefinition getDefinition(sal_uInt32 nFeatureCode);
diff --git a/vcl/inc/font/OpenTypeFeatureStrings.hrc b/vcl/inc/font/OpenTypeFeatureStrings.hrc
index 3ed3df4b90f4..a3d2179ceea7 100644
--- a/vcl/inc/font/OpenTypeFeatureStrings.hrc
+++ b/vcl/inc/font/OpenTypeFeatureStrings.hrc
@@ -33,17 +33,7 @@
#define STR_FONT_FEATURE_ID_CPCT NC_("STR_FONT_FEATURE_ID_CPCT", "Centered CJK Punctuation")
#define STR_FONT_FEATURE_ID_CPSP NC_("STR_FONT_FEATURE_ID_CPSP", "Capital Spacing")
#define STR_FONT_FEATURE_ID_CSWH NC_("STR_FONT_FEATURE_ID_CSWH", "Contextual Swash")
-#define STR_FONT_FEATURE_ID_CV01 NC_("STR_FONT_FEATURE_ID_CV01", "Character Variant 1")
-#define STR_FONT_FEATURE_ID_CV02 NC_("STR_FONT_FEATURE_ID_CV02", "Character Variant 2")
-#define STR_FONT_FEATURE_ID_CV03 NC_("STR_FONT_FEATURE_ID_CV03", "Character Variant 3")
-#define STR_FONT_FEATURE_ID_CV04 NC_("STR_FONT_FEATURE_ID_CV04", "Character Variant 4")
-#define STR_FONT_FEATURE_ID_CV05 NC_("STR_FONT_FEATURE_ID_CV05", "Character Variant 5")
-#define STR_FONT_FEATURE_ID_CV06 NC_("STR_FONT_FEATURE_ID_CV06", "Character Variant 6")
-#define STR_FONT_FEATURE_ID_CV07 NC_("STR_FONT_FEATURE_ID_CV07", "Character Variant 7")
-#define STR_FONT_FEATURE_ID_CV08 NC_("STR_FONT_FEATURE_ID_CV08", "Character Variant 8")
-#define STR_FONT_FEATURE_ID_CV09 NC_("STR_FONT_FEATURE_ID_CV09", "Character Variant 9")
-#define STR_FONT_FEATURE_ID_CV10 NC_("STR_FONT_FEATURE_ID_CV10", "Character Variant 10")
-#define STR_FONT_FEATURE_ID_CV11 NC_("STR_FONT_FEATURE_ID_CV11", "Character Variant 11")
+#define STR_FONT_FEATURE_ID_CVXX NC_("STR_FONT_FEATURE_ID_CVXX", "Character Variant %1")
#define STR_FONT_FEATURE_ID_DCAP NC_("STR_FONT_FEATURE_ID_DCAP", "Drop Caps")
#define STR_FONT_FEATURE_ID_DLIG NC_("STR_FONT_FEATURE_ID_DLIG", "Discretionary Ligatures")
#define STR_FONT_FEATURE_ID_DNOM NC_("STR_FONT_FEATURE_ID_DNOM", "Denominators")
@@ -91,26 +81,7 @@
#define STR_FONT_FEATURE_ID_SINF NC_("STR_FONT_FEATURE_ID_SINF", "Scientific Inferiors")
#define STR_FONT_FEATURE_ID_SMCP NC_("STR_FONT_FEATURE_ID_SMCP", "Lowercase to Small Capitals")
#define STR_FONT_FEATURE_ID_SMPL NC_("STR_FONT_FEATURE_ID_SMPL", "Simplified Forms")
-#define STR_FONT_FEATURE_ID_SS01 NC_("STR_FONT_FEATURE_ID_SS01", "Stylistic Set 1")
-#define STR_FONT_FEATURE_ID_SS02 NC_("STR_FONT_FEATURE_ID_SS02", "Stylistic Set 2")
-#define STR_FONT_FEATURE_ID_SS03 NC_("STR_FONT_FEATURE_ID_SS03", "Stylistic Set 3")
-#define STR_FONT_FEATURE_ID_SS04 NC_("STR_FONT_FEATURE_ID_SS04", "Stylistic Set 4")
-#define STR_FONT_FEATURE_ID_SS05 NC_("STR_FONT_FEATURE_ID_SS05", "Stylistic Set 5")
-#define STR_FONT_FEATURE_ID_SS06 NC_("STR_FONT_FEATURE_ID_SS06", "Stylistic Set 6")
-#define STR_FONT_FEATURE_ID_SS07 NC_("STR_FONT_FEATURE_ID_SS07", "Stylistic Set 7")
-#define STR_FONT_FEATURE_ID_SS08 NC_("STR_FONT_FEATURE_ID_SS08", "Stylistic Set 8")
-#define STR_FONT_FEATURE_ID_SS09 NC_("STR_FONT_FEATURE_ID_SS09", "Stylistic Set 9")
-#define STR_FONT_FEATURE_ID_SS10 NC_("STR_FONT_FEATURE_ID_SS10", "Stylistic Set 10")
-#define STR_FONT_FEATURE_ID_SS11 NC_("STR_FONT_FEATURE_ID_SS11", "Stylistic Set 11")
-#define STR_FONT_FEATURE_ID_SS12 NC_("STR_FONT_FEATURE_ID_SS12", "Stylistic Set 12")
-#define STR_FONT_FEATURE_ID_SS13 NC_("STR_FONT_FEATURE_ID_SS13", "Stylistic Set 13")
-#define STR_FONT_FEATURE_ID_SS14 NC_("STR_FONT_FEATURE_ID_SS14", "Stylistic Set 14")
-#define STR_FONT_FEATURE_ID_SS15 NC_("STR_FONT_FEATURE_ID_SS15", "Stylistic Set 15")
-#define STR_FONT_FEATURE_ID_SS16 NC_("STR_FONT_FEATURE_ID_SS16", "Stylistic Set 16")
-#define STR_FONT_FEATURE_ID_SS17 NC_("STR_FONT_FEATURE_ID_SS17", "Stylistic Set 17")
-#define STR_FONT_FEATURE_ID_SS18 NC_("STR_FONT_FEATURE_ID_SS18", "Stylistic Set 18")
-#define STR_FONT_FEATURE_ID_SS19 NC_("STR_FONT_FEATURE_ID_SS19", "Stylistic Set 19")
-#define STR_FONT_FEATURE_ID_SS20 NC_("STR_FONT_FEATURE_ID_SS20", "Stylistic Set 20")
+#define STR_FONT_FEATURE_ID_SSXX NC_("STR_FONT_FEATURE_ID_SSXX", "Stylistic Set %1")
#define STR_FONT_FEATURE_ID_SUBS NC_("STR_FONT_FEATURE_ID_SUBS", "Subscript")
#define STR_FONT_FEATURE_ID_SUPS NC_("STR_FONT_FEATURE_ID_SUPS", "Superscript")
#define STR_FONT_FEATURE_ID_SWSH NC_("STR_FONT_FEATURE_ID_SWSH", "Swash")
diff --git a/vcl/source/font/Feature.cxx b/vcl/source/font/Feature.cxx
index 1b7545b560b9..a23a85fae952 100644
--- a/vcl/source/font/Feature.cxx
+++ b/vcl/source/font/Feature.cxx
@@ -76,9 +76,11 @@ FeatureDefinition::FeatureDefinition(sal_uInt32 nCode, OUString const& rDescript
{
}
-FeatureDefinition::FeatureDefinition(sal_uInt32 nCode, const char* pDescriptionID)
+FeatureDefinition::FeatureDefinition(sal_uInt32 nCode, const char* pDescriptionID,
+ OUString const& rNumericPart)
: m_nCode(nCode)
, m_pDescriptionID(pDescriptionID)
+ , m_sNumericPart(rNumericPart)
, m_eType(FeatureParameterType::BOOL)
{
}
@@ -100,11 +102,20 @@ const std::vector<FeatureParameter>& FeatureDefinition::getEnumParameters() cons
OUString FeatureDefinition::getDescription() const
{
if (m_pDescriptionID)
- return VclResId(m_pDescriptionID);
+ {
+ OUString sTranslatedDescription = VclResId(m_pDescriptionID);
+ if (!m_sNumericPart.isEmpty())
+ return sTranslatedDescription.replaceFirst("%1", m_sNumericPart);
+ return sTranslatedDescription;
+ }
else if (!m_sDescription.isEmpty())
+ {
return m_sDescription;
+ }
else
+ {
return vcl::font::featureCodeAsString(m_nCode);
+ }
}
sal_uInt32 FeatureDefinition::getCode() const { return m_nCode; }
diff --git a/vcl/source/font/OpenTypeFeatureDefinitonList.cxx b/vcl/source/font/OpenTypeFeatureDefinitonList.cxx
index 8b5ce4858956..1c75d46031c7 100644
--- a/vcl/source/font/OpenTypeFeatureDefinitonList.cxx
+++ b/vcl/source/font/OpenTypeFeatureDefinitonList.cxx
@@ -12,6 +12,8 @@
#include <font/OpenTypeFeatureStrings.hrc>
#include <svdata.hxx>
+#include <rtl/character.hxx>
+
namespace vcl
{
namespace font
@@ -32,15 +34,6 @@ void OpenTypeFeatureDefinitonListPrivate::init()
{ featureCode("cpct"), STR_FONT_FEATURE_ID_CPCT },
{ featureCode("cpsp"), STR_FONT_FEATURE_ID_CPSP },
{ featureCode("cswh"), STR_FONT_FEATURE_ID_CSWH },
- { featureCode("cv01"), STR_FONT_FEATURE_ID_CV01 },
- { featureCode("cv02"), STR_FONT_FEATURE_ID_CV02 },
- { featureCode("cv03"), STR_FONT_FEATURE_ID_CV03 },
- { featureCode("cv04"), STR_FONT_FEATURE_ID_CV04 },
- { featureCode("cv05"), STR_FONT_FEATURE_ID_CV05 },
- { featureCode("cv06"), STR_FONT_FEATURE_ID_CV06 },
- { featureCode("cv07"), STR_FONT_FEATURE_ID_CV07 },
- { featureCode("cv08"), STR_FONT_FEATURE_ID_CV08 },
- { featureCode("cv09"), STR_FONT_FEATURE_ID_CV09 },
{ featureCode("dcap"), STR_FONT_FEATURE_ID_DCAP },
{ featureCode("dlig"), STR_FONT_FEATURE_ID_DLIG },
{ featureCode("dnom"), STR_FONT_FEATURE_ID_DNOM },
@@ -88,26 +81,6 @@ void OpenTypeFeatureDefinitonListPrivate::init()
{ featureCode("sinf"), STR_FONT_FEATURE_ID_SINF },
{ featureCode("smcp"), STR_FONT_FEATURE_ID_SMCP },
{ featureCode("smpl"), STR_FONT_FEATURE_ID_SMPL },
- { featureCode("ss01"), STR_FONT_FEATURE_ID_SS01 },
- { featureCode("ss02"), STR_FONT_FEATURE_ID_SS02 },
- { featureCode("ss03"), STR_FONT_FEATURE_ID_SS03 },
- { featureCode("ss04"), STR_FONT_FEATURE_ID_SS04 },
- { featureCode("ss05"), STR_FONT_FEATURE_ID_SS05 },
- { featureCode("ss06"), STR_FONT_FEATURE_ID_SS06 },
- { featureCode("ss07"), STR_FONT_FEATURE_ID_SS07 },
- { featureCode("ss08"), STR_FONT_FEATURE_ID_SS08 },
- { featureCode("ss09"), STR_FONT_FEATURE_ID_SS09 },
- { featureCode("ss10"), STR_FONT_FEATURE_ID_SS10 },
- { featureCode("ss11"), STR_FONT_FEATURE_ID_SS11 },
- { featureCode("ss12"), STR_FONT_FEATURE_ID_SS12 },
- { featureCode("ss13"), STR_FONT_FEATURE_ID_SS13 },
- { featureCode("ss14"), STR_FONT_FEATURE_ID_SS14 },
- { featureCode("ss15"), STR_FONT_FEATURE_ID_SS15 },
- { featureCode("ss16"), STR_FONT_FEATURE_ID_SS16 },
- { featureCode("ss17"), STR_FONT_FEATURE_ID_SS17 },
- { featureCode("ss18"), STR_FONT_FEATURE_ID_SS18 },
- { featureCode("ss19"), STR_FONT_FEATURE_ID_SS19 },
- { featureCode("ss20"), STR_FONT_FEATURE_ID_SS20 },
{ featureCode("subs"), STR_FONT_FEATURE_ID_SUBS },
{ featureCode("sups"), STR_FONT_FEATURE_ID_SUPS },
{ featureCode("swsh"), STR_FONT_FEATURE_ID_SWSH },
@@ -149,8 +122,62 @@ void OpenTypeFeatureDefinitonListPrivate::init()
});
}
+namespace
+{
+bool isCharacterVariantCode(sal_uInt32 nFeatureCode)
+{
+ return sal_Char((sal_uInt32(nFeatureCode) >> 24) & 0xFF) == 'c'
+ && sal_Char((sal_uInt32(nFeatureCode) >> 16) & 0xFF) == 'v';
+}
+
+bool isStylisticSetCode(sal_uInt32 nFeatureCode)
+{
+ return sal_Char((sal_uInt32(nFeatureCode) >> 24) & 0xFF) == 's'
+ && sal_Char((sal_uInt32(nFeatureCode) >> 16) & 0xFF) == 's';
+}
+
+OUString getNumericLowerPart(sal_uInt32 nFeatureCode)
+{
+ sal_Char cChar1((sal_uInt32(nFeatureCode) >> 8) & 0xFF);
+ sal_Char cChar2((sal_uInt32(nFeatureCode) >> 0) & 0xFF);
+
+ if (rtl::isAsciiDigit(static_cast<unsigned char>(cChar1))
+ && rtl::isAsciiDigit(static_cast<unsigned char>(cChar2)))
+ {
+ return OUString(cChar1) + OUString(cChar2);
+ }
+ return OUString();
+}
+
+} // end anonymous namespace
+
+bool OpenTypeFeatureDefinitonListPrivate::isSpecialFeatureCode(sal_uInt32 nFeatureCode)
+{
+ return isCharacterVariantCode(nFeatureCode) || isStylisticSetCode(nFeatureCode);
+}
+
+FeatureDefinition
+OpenTypeFeatureDefinitonListPrivate::handleSpecialFeatureCode(sal_uInt32 nFeatureCode)
+{
+ FeatureDefinition aFeatureDefinition;
+ OUString sNumericPart = getNumericLowerPart(nFeatureCode);
+ if (!sNumericPart.isEmpty())
+ {
+ if (isCharacterVariantCode(nFeatureCode))
+ aFeatureDefinition = { nFeatureCode, STR_FONT_FEATURE_ID_SSXX, sNumericPart };
+ else if (isStylisticSetCode(nFeatureCode))
+ aFeatureDefinition = { nFeatureCode, STR_FONT_FEATURE_ID_CVXX, sNumericPart };
+ }
+ return aFeatureDefinition;
+}
+
FeatureDefinition OpenTypeFeatureDefinitonListPrivate::getDefinition(sal_uInt32 nFeatureCode)
{
+ if (isSpecialFeatureCode(nFeatureCode))
+ {
+ return handleSpecialFeatureCode(nFeatureCode);
+ }
+
if (m_aCodeToIndex.find(nFeatureCode) != m_aCodeToIndex.end())
{
size_t nIndex = m_aCodeToIndex.at(nFeatureCode);
More information about the Libreoffice-commits
mailing list