skia2/include/core/SkFontStyle.h
Mike Klein d9187c085b Revert "SkMath takes some functions from from SkTypes"
This reverts commit 3b347232bc.

Reason for revert: tree done gone red.

Original change's description:
> SkMath takes some functions from from SkTypes
> 
> Moved to include/core/SkMath.h: Sk{Is|}Align{2|4|8|Ptr}, SkLeftShift,
> SkAbs{32|}, SkM{ax|in}32 SkTM{in|ax}, SkTClamp, SkFastMin32, SkTPin.
> 
> Change-Id: Ibcc07be0fc3677731048e7cc86006e7aa493cb92
> Reviewed-on: https://skia-review.googlesource.com/133381
> Auto-Submit: Hal Canary <halcanary@google.com>
> Reviewed-by: Ben Wagner <bungeman@google.com>
> Commit-Queue: Hal Canary <halcanary@google.com>

TBR=mtklein@google.com,halcanary@google.com,bungeman@google.com,reed@google.com

Change-Id: I44073cf397e2a3a6a941a90f0aa63c6396d4c742
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/152587
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
2018-09-07 17:32:54 +00:00

81 lines
2.3 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkFontStyle_DEFINED
#define SkFontStyle_DEFINED
#include "SkTypes.h"
class SK_API SkFontStyle {
public:
enum Weight {
kInvisible_Weight = 0,
kThin_Weight = 100,
kExtraLight_Weight = 200,
kLight_Weight = 300,
kNormal_Weight = 400,
kMedium_Weight = 500,
kSemiBold_Weight = 600,
kBold_Weight = 700,
kExtraBold_Weight = 800,
kBlack_Weight = 900,
kExtraBlack_Weight = 1000,
};
enum Width {
kUltraCondensed_Width = 1,
kExtraCondensed_Width = 2,
kCondensed_Width = 3,
kSemiCondensed_Width = 4,
kNormal_Width = 5,
kSemiExpanded_Width = 6,
kExpanded_Width = 7,
kExtraExpanded_Width = 8,
kUltraExpanded_Width = 9,
};
enum Slant {
kUpright_Slant,
kItalic_Slant,
kOblique_Slant,
};
constexpr SkFontStyle(int weight, int width, Slant slant) : fValue(
(SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight)) +
(SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width) << 16) +
(SkTPin<int>(slant, kUpright_Slant, kOblique_Slant) << 24)
) { }
constexpr SkFontStyle() : SkFontStyle{kNormal_Weight, kNormal_Width, kUpright_Slant} { }
bool operator==(const SkFontStyle& rhs) const {
return fValue == rhs.fValue;
}
int weight() const { return fValue & 0xFFFF; }
int width() const { return (fValue >> 16) & 0xFF; }
Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); }
static constexpr SkFontStyle Normal() {
return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant);
}
static constexpr SkFontStyle Bold() {
return SkFontStyle(kBold_Weight, kNormal_Width, kUpright_Slant);
}
static constexpr SkFontStyle Italic() {
return SkFontStyle(kNormal_Weight, kNormal_Width, kItalic_Slant );
}
static constexpr SkFontStyle BoldItalic() {
return SkFontStyle(kBold_Weight, kNormal_Width, kItalic_Slant );
}
private:
uint32_t fValue;
};
#endif