public static MakeFontSizePtUnit ( float pointUnit ) : |
||
pointUnit | float | |
return |
internal RequestFont GetFont(float parentFontSize) { if (_reqFont != null) { return(_reqFont); } bool relateToParent = false; string fontFam = this.FontFamily; if (string.IsNullOrEmpty(FontFamily)) { fontFam = FontDefaultConfig.DEFAULT_FONT_NAME; } //----------------------------------------------------------------------------- //style FontStyle st = PixelFarm.Drawing.FontStyle.Regular; switch (FontStyle) { case CssFontStyle.Italic: case CssFontStyle.Oblique: st |= PixelFarm.Drawing.FontStyle.Italic; break; } //----------------------------------------------------- //weight CssFontWeight fontWight = this.FontWeight; switch (this.FontWeight) { case CssFontWeight.Normal: case CssFontWeight.Lighter: case CssFontWeight.NotAssign: case CssFontWeight.Inherit: { //do nothing } break; default: { st |= PixelFarm.Drawing.FontStyle.Bold; } break; } CssLength fontsize = this.FontSize; if (fontsize.IsEmpty || fontsize.Number == 0) { fontsize = CssLength.MakeFontSizePtUnit(FontDefaultConfig.DEFAULT_FONT_SIZE); } float fsize = FontDefaultConfig.DEFAULT_FONT_SIZE; if (fontsize.IsFontSizeName) { switch (fontsize.UnitOrNames) { case CssUnitOrNames.FONTSIZE_MEDIUM: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE; break; case CssUnitOrNames.FONTSIZE_XX_SMALL: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE - 4; break; case CssUnitOrNames.FONTSIZE_X_SMALL: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE - 3; break; case CssUnitOrNames.FONTSIZE_LARGE: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE + 2; break; case CssUnitOrNames.FONTSIZE_X_LARGE: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE + 3; break; case CssUnitOrNames.FONTSIZE_XX_LARGE: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE + 4; break; case CssUnitOrNames.FONTSIZE_SMALLER: { relateToParent = true; //float parentFontSize = ConstConfig.DEFAULT_FONT_SIZE; //if (parentBox != null) //{ // parentFontSize = parentBox._actualFont.Size; //} fsize = parentFontSize - 2; } break; case CssUnitOrNames.FONTSIZE_LARGER: { relateToParent = true; //float parentFontSize = ConstConfig.DEFAULT_FONT_SIZE; //if (parentBox != null) //{ // parentFontSize = parentBox._actualFont.Size; //} fsize = parentFontSize + 2; } break; default: throw new NotSupportedException(); } } else { fsize = fontsize.Number; } if (fontsize.UnitOrNames == CssUnitOrNames.Ems) { fsize = fontsize.Number * FontDefaultConfig.DEFAULT_FONT_SIZE; relateToParent = true; } if (fsize <= 1f) { fsize = FontDefaultConfig.DEFAULT_FONT_SIZE; } _reqFont = new RequestFont(fontFam, fsize, st); //resolve //TODO: review here again //review font resolve here... //throw new NotFiniteNumberException(); //ActualFontResolver.Resolver.Resolve(_reqFont); return(_reqFont); }
internal FontInfo GetFontInfo(IFonts ifonts, float parentFontSize) { //--------------------------------------- if (_actualFontInfo != null) { return(this._actualFontInfo); } //--------------------------------------- bool relateToParent = false; string fontFam = this.FontFamily; if (string.IsNullOrEmpty(FontFamily)) { fontFam = FontDefaultConfig.DEFAULT_FONT_NAME; } //----------------------------------------------------------------------------- //style FontStyle st = PixelFarm.Drawing.FontStyle.Regular; switch (FontStyle) { case CssFontStyle.Italic: case CssFontStyle.Oblique: st |= PixelFarm.Drawing.FontStyle.Italic; break; } //----------------------------------------------------- //weight CssFontWeight fontWight = this.FontWeight; switch (this.FontWeight) { case CssFontWeight.Normal: case CssFontWeight.Lighter: case CssFontWeight.NotAssign: case CssFontWeight.Inherit: { //do nothing } break; default: { st |= PixelFarm.Drawing.FontStyle.Bold; } break; } CssLength fontsize = this.FontSize; if (fontsize.IsEmpty || fontsize.Number == 0) { fontsize = CssLength.MakeFontSizePtUnit(FontDefaultConfig.DEFAULT_FONT_SIZE); } float fsize = FontDefaultConfig.DEFAULT_FONT_SIZE; if (fontsize.IsFontSizeName) { switch (fontsize.UnitOrNames) { case CssUnitOrNames.FONTSIZE_MEDIUM: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE; break; case CssUnitOrNames.FONTSIZE_XX_SMALL: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE - 4; break; case CssUnitOrNames.FONTSIZE_X_SMALL: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE - 3; break; case CssUnitOrNames.FONTSIZE_LARGE: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE + 2; break; case CssUnitOrNames.FONTSIZE_X_LARGE: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE + 3; break; case CssUnitOrNames.FONTSIZE_XX_LARGE: fsize = FontDefaultConfig.DEFAULT_FONT_SIZE + 4; break; case CssUnitOrNames.FONTSIZE_SMALLER: { relateToParent = true; //float parentFontSize = ConstConfig.DEFAULT_FONT_SIZE; //if (parentBox != null) //{ // parentFontSize = parentBox._actualFont.Size; //} fsize = parentFontSize - 2; } break; case CssUnitOrNames.FONTSIZE_LARGER: { relateToParent = true; //float parentFontSize = ConstConfig.DEFAULT_FONT_SIZE; //if (parentBox != null) //{ // parentFontSize = parentBox._actualFont.Size; //} fsize = parentFontSize + 2; } break; default: throw new NotSupportedException(); } } else { fsize = fontsize.Number; } if (fontsize.UnitOrNames == CssUnitOrNames.Ems) { fsize = fontsize.Number * FontDefaultConfig.DEFAULT_FONT_SIZE; relateToParent = true; } if (fsize <= 1f) { fsize = FontDefaultConfig.DEFAULT_FONT_SIZE; } FontInfo fontInfo = ifonts.GetFontInfo(fontFam, fsize, st); if (!relateToParent) { //cahce value this._actualFont = fontInfo.ResolvedFont; this._actualFontInfo = fontInfo; } return(fontInfo); }