public RequestFont(string fontFamily, Len fontSize, ushort fontWeight = 400, RequestFontStyle cssFontStyle = RequestFontStyle.Regular) { //ctor of the RequestFont supports CSS's style font-family //font-family: Red/Black, sans-serif; //font-family: "Lucida" Grande, sans-serif //font-family: Ahem!, sans-serif //font-family: test@foo, sans-serif //font-family: #POUND, sans-serif //font-family: Hawaii 5-0, sans-serif //*** the first one will be primary font //and the other will be our choice //see https://www.w3.org/TR/css-fonts-3/ //<family-name> // The name of a font family of choice such as Helvetica or Verdana in the previous example. //<generic-family> // The following generic family keywords are defined: ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, and ‘monospace’. // These keywords can be used as a general fallback mechanism when an author's desired font choices are not available. // As keywords, they must not be quoted. // Authors are encouraged to append a generic font family as a last alternative for improved robustness. Size = fontSize; //store user font size here SizeInPoints = fontSize.ToPoints(); //parse the font family name //TODO: use CSS parse code? string[] splitedNames = fontFamily.Split(','); #if DEBUG if (splitedNames.Length == 0) { throw new NotSupportedException(); } #endif Name = splitedNames[0].Trim(); //store with case sensitive (as original data)***, but search with case-insensitive if (splitedNames.Length > 1) { _otherChoices = new List <Choice>(); for (int i = 1; i < splitedNames.Length; ++i) { string name = splitedNames[i].Trim(); //store with case sensitive (as original data)***, but search with case-insensitive if (name.Length == 0) { continue; } _otherChoices.Add(new Choice(name, fontSize)); } } Style = cssFontStyle; }
public Choice(string fontFamily, Len fontSize, ushort fontWeight = 400, RequestFontStyle cssFontStyle = RequestFontStyle.Regular) { Size = fontSize; //store user font size here SizeInPoints = fontSize.ToPoints(); #if DEBUG if (fontFamily.Contains(",")) { throw new NotSupportedException(); } //ONLY 1 name #endif Name = fontFamily.Trim(); //ONLY 1 name Style = cssFontStyle; }
public RequestFont(string fontFamily, float fontSizeInPts, ushort fontWeight = 400, RequestFontStyle cssFontStyle = RequestFontStyle.Regular) : this(fontFamily, Len.Pt(fontSizeInPts), fontWeight, cssFontStyle) { }
public static Typography.FontCollections.TypefaceStyle ConvToInstalledFontStyle(this RequestFontStyle style) { switch (style) { default: case RequestFontStyle.Regular: return(Typography.FontCollections.TypefaceStyle.Regular); case RequestFontStyle.Italic: return(Typography.FontCollections.TypefaceStyle.Italic); case RequestFontStyle.Oblique: return(Typography.FontCollections.TypefaceStyle.Italic); } }