1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkFontStyle.h"
9 #include "SkTypeface.h"
10 #include "SkTypes.h"
11 
SkFontStyle()12 SkFontStyle::SkFontStyle() {
13     fUnion.fU32 = 0;
14     fUnion.fR.fWeight = kNormal_Weight;
15     fUnion.fR.fWidth = kNormal_Width;
16     fUnion.fR.fSlant = kUpright_Slant;
17 }
18 
SkFontStyle(int weight,int width,Slant slant)19 SkFontStyle::SkFontStyle(int weight, int width, Slant slant) {
20     fUnion.fU32 = 0;
21     fUnion.fR.fWeight = SkTPin<int>(weight, kThin_Weight, kBlack_Weight);
22     fUnion.fR.fWidth = SkTPin<int>(width, kUltraCondensed_Width, kUltaExpanded_Width);
23     fUnion.fR.fSlant = SkTPin<int>(slant, kUpright_Slant, kItalic_Slant);
24 }
25 
SkFontStyle(unsigned oldStyle)26 SkFontStyle::SkFontStyle(unsigned oldStyle) {
27     fUnion.fU32 = 0;
28     fUnion.fR.fWeight = (oldStyle & SkTypeface::kBold) ? SkFontStyle::kBold_Weight
29                                                        : SkFontStyle::kNormal_Weight;
30     fUnion.fR.fWidth = SkFontStyle::kNormal_Width;
31     fUnion.fR.fSlant = (oldStyle & SkTypeface::kItalic) ? SkFontStyle::kItalic_Slant
32                                                         : SkFontStyle::kUpright_Slant;
33 }
34