public static float ConvertToPxWithFontAdjust(CssLength length, float hundredPercent, CssBox box) { //Return zero if no length specified, zero specified switch (length.UnitOrNames) { case CssUnitOrNames.EmptyValue: return 0; case CssUnitOrNames.Percent: return (length.Number / 100f) * hundredPercent; case CssUnitOrNames.Ems: return length.Number * box.GetEmHeight(); case CssUnitOrNames.Ex: return length.Number * (box.GetEmHeight() / 2); case CssUnitOrNames.Pixels: //atodo: check support for hi dpi return length.Number * (72f / 96f); //font adjust case CssUnitOrNames.Milimeters: return length.Number * 3.779527559f; //3 pixels per millimeter case CssUnitOrNames.Centimeters: return length.Number * 37.795275591f; //37 pixels per centimeter case CssUnitOrNames.Inches: return length.Number * 96f; //96 pixels per inch case CssUnitOrNames.Points: return length.Number * (96f / 72f); // 1 point = 1/72 of inch case CssUnitOrNames.Picas: return length.Number * 16f; // 1 pica = 12 points default: return 0; } }
public static float ConvertToPx(CssLength length, ref ReEvaluateArgs args) { //Return zero if no length specified, zero specified switch (length.UnitOrNames) { case CssUnitOrNames.EmptyValue: return 0; case CssUnitOrNames.Percent: return (length.Number / 100f) * args.containerW; case CssUnitOrNames.Ems: return length.Number * args.emHeight; case CssUnitOrNames.Ex: return length.Number * (args.emHeight / 2); case CssUnitOrNames.Pixels: //atodo: check support for hi dpi return length.Number; case CssUnitOrNames.Milimeters: return length.Number * 3.779527559f; //3 pixels per millimeter case CssUnitOrNames.Centimeters: return length.Number * 37.795275591f; //37 pixels per centimeter case CssUnitOrNames.Inches: return length.Number * 96f; //96 pixels per inch case CssUnitOrNames.Points: return length.Number * (96f / 72f); // 1 point = 1/72 of inch case CssUnitOrNames.Picas: return length.Number * 16f; // 1 pica = 12 points default: return 0; } }
public static bool dbugIsEq(dbugPropCheckReport rep, CssPaddingFeature prop1, CssPaddingFeature prop2) { int inCount = rep.Count; rep.Check("Left", CssLength.IsEq(prop1.Left, prop2.Left)); rep.Check("Top", CssLength.IsEq(prop1.Top, prop2.Top)); rep.Check("Right", CssLength.IsEq(prop1.Right, prop2.Right)); rep.Check("Bottom", CssLength.IsEq(prop1.Bottom, prop2.Bottom)); return(inCount == rep.Count); }
public static bool dbugIsEq(dbugPropCheckReport rep, CssCornerFeature prop1, CssCornerFeature prop2) { int inCount = rep.Count; rep.Check("NERadius", CssLength.IsEq(prop1.NERadius, prop2.NERadius)); rep.Check("NWRadius", CssLength.IsEq(prop1.NWRadius, prop2.NWRadius)); rep.Check("SERadius", CssLength.IsEq(prop1.SERadius, prop2.SERadius)); rep.Check("SWRadius", CssLength.IsEq(prop1.SWRadius, prop2.SWRadius)); return(inCount == rep.Count); }
//---------------------------------------------------------------------- #if DEBUG public static bool dbugCompare(dbugPropCheckReport dbugR, BoxSpec boxBase, BoxSpec spec) { int dd = boxBase.__aa_dbugId; dbugR.Check("_fontProps", CssFontFeature.dbugIsEq(dbugR, boxBase._fontFeats, spec._fontFeats)); dbugR.Check("_listProps", CssListFeature.dbugIsEq(dbugR, boxBase._listFeats, spec._listFeats)); dbugR.Check("_lineHeight", CssLength.IsEq(boxBase._lineHeight, spec._lineHeight)); dbugR.Check("_textIndent", CssLength.IsEq(boxBase._textIndent, spec._textIndent)); dbugR.Check("_actualColor", boxBase._actualColor == spec._actualColor); dbugR.Check("_emptyCells", boxBase._emptyCells == spec._emptyCells); dbugR.Check("_textAlign", boxBase._textAlign == spec._textAlign); dbugR.Check("_verticalAlign", boxBase._verticalAlign == spec._verticalAlign); dbugR.Check("_visibility", boxBase._visibility == spec._visibility); dbugR.Check("_whitespace", boxBase._whitespace == spec._whitespace); dbugR.Check("_wordBreak", boxBase._wordBreak == spec._wordBreak); dbugR.Check("_cssDirection", boxBase._cssDirection == spec._cssDirection); dbugR.Check("_backgroundProps", CssBackgroundFeature.dbugIsEq(dbugR, boxBase._backgroundFeats, spec._backgroundFeats)); dbugR.Check("_borderProps", CssBorderFeature.dbugIsEq(dbugR, boxBase._borderFeats, spec._borderFeats)); dbugR.Check("_cornerProps", CssCornerFeature.dbugIsEq(dbugR, boxBase._cornerFeats, spec._cornerFeats)); //--------------------------------------- dbugR.Check("_left", CssLength.IsEq(boxBase._left, spec._left)); dbugR.Check("_top", CssLength.IsEq(boxBase._top, spec._top)); dbugR.Check("_bottom", CssLength.IsEq(boxBase._bottom, spec._bottom)); dbugR.Check("_right", CssLength.IsEq(boxBase._right, spec._right)); dbugR.Check("_width", CssLength.IsEq(boxBase._width, spec._width)); dbugR.Check("_height", CssLength.IsEq(boxBase._height, spec._height)); dbugR.Check("_maxWidth", CssLength.IsEq(boxBase._maxWidth, spec._maxWidth)); dbugR.Check("_position", boxBase._position == spec._position); dbugR.Check("_wordSpacing", CssLength.IsEq(boxBase._wordSpacing, spec._wordSpacing)); dbugR.Check("_float", boxBase._float == spec._float); dbugR.Check("_cssDisplay", boxBase._cssDisplay == spec._cssDisplay); dbugR.Check("_overflow", boxBase._overflow == spec._overflow); dbugR.Check("_textDecoration", boxBase._textDecoration == spec._textDecoration); if (dbugR.Count > 0) { return(false); } return(true); }
public static bool dbugIsEq(dbugPropCheckReport rep, CssFontFeature prop1, CssFontFeature prop2) { if (prop1 == prop2) { return(true); } //---------------- int inCount = rep.Count; rep.Check("FontFamily", prop1.FontFamily == prop2.FontFamily); rep.Check("FontSize", CssLength.IsEq(prop1.FontSize, prop2.FontSize)); rep.Check("FontStyle", prop1.FontStyle == prop2.FontStyle); rep.Check("FontVariant", prop1.FontVariant == prop2.FontVariant); rep.Check("FontWeight", prop1.FontWeight == prop2.FontWeight); return(inCount == rep.Count); }
public static bool dbugIsEq(dbugPropCheckReport rep, CssBorderFeature prop1, CssBorderFeature prop2) { int inCount = rep.Count; rep.Check("LeftWidth", CssLength.IsEq(prop1.LeftWidth, prop2.LeftWidth)); rep.Check("TopWidth", CssLength.IsEq(prop1.TopWidth, prop2.TopWidth)); rep.Check("RightWidth", CssLength.IsEq(prop1.RightWidth, prop2.RightWidth)); rep.Check("BottomWidth", CssLength.IsEq(prop1.BottomWidth, prop2.BottomWidth)); rep.Check("LeftStyle", prop1.LeftStyle == prop2.LeftStyle); rep.Check("TopStyle", prop1.TopStyle == prop2.TopStyle); rep.Check("RightStyle", prop1.RightStyle == prop2.RightStyle); rep.Check("BottomStyle", prop1.BottomStyle == prop2.BottomStyle); rep.Check("LeftColor", prop1.LeftColor == prop2.LeftColor); rep.Check("TopColor", prop1.TopColor == prop2.TopColor); rep.Check("RightColor", prop1.RightColor == prop2.RightColor); rep.Check("BottomColor", prop1.BottomColor == prop2.BottomColor); rep.Check("BorderCollapse", prop1.BorderCollapse == prop2.BorderCollapse); rep.Check("BorderSpacingH", CssLength.IsEq(prop1.BorderSpacingH, prop2.BorderSpacingH)); rep.Check("BorderSpacingV", CssLength.IsEq(prop1.BorderSpacingV, prop2.BorderSpacingV)); return(inCount == rep.Count); }
public static float GetActualBorderWidth(CssLength borderValue, CssBox b) { //------------------------------ //plan: use extended cssunit //------------------------------ switch (borderValue.UnitOrNames) { case CssUnitOrNames.EmptyValue://as medium case CssUnitOrNames.BorderMedium: return 2f; case CssUnitOrNames.BorderThin: return 1f; case CssUnitOrNames.BorderThick: return 4f; default: return Math.Abs(ConvertToPx(borderValue, 1, b)); } }
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); }
public void SetCssLength(CssLength len, WebDom.CssValueEvaluatedAs evalAs) { _cachedLength = len; _evaluatedAs = evalAs; }
/// <summary> /// recalculate padding /// </summary> /// <param name="padding"></param> /// <param name="cbWidth"></param> /// <returns></returns> float RecalculatePadding(CssLength padding, float cbWidth) { //www.w3.org/TR/CSS2/box.html#padding-properties if (padding.IsAuto) { return 0; } return CssValueParser.ConvertToPx(padding, cbWidth, this); }
//============================================================= /// <summary> /// recalculate margin /// </summary> /// <param name="margin">marin side</param> /// <param name="cbWidth">width of containging block</param> /// <returns></returns> float RecalculateMargin(CssLength margin, float cbWidth) { //www.w3.org/TR/CSS2/box.html#margin-properties if (margin.IsAuto) { return 0; } return CssValueParser.ConvertToPx(margin, cbWidth, this); }
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); }
static CssLength SetLineHeight(this CssBox box, CssLength len) { //2014,2015, //from www.w3c.org/wiki/Css/Properties/line-height //line height in <percentage> : //The computed value if the property is percentage multiplied by the //element's computed font size. return CssLength.MakePixelLength( CssValueParser.ConvertToPx(len, box.GetEmHeight(), box)); }
public void SetCssLength(CssLength len, WebDom.CssValueEvaluatedAs evalAs) { this.cachedLength = len; this.evaluatedAs = evalAs; }
public static bool IsEq(CssLength len1, CssLength len2) { return (len1._number == len2.Number) && (len1._flags == len2._flags); }
private static CssLength TranslateLength(CssLength len) { if (len.HasError) { //if unknown unit number return CssLength.MakePixelLength(len.Number); } return len; }
public static bool IsEq(CssLength len1, CssLength len2) { return((len1._number == len2.Number) && (len1._flags == len2._flags)); }
/// <summary> /// Get top-left location to start drawing the image at depending on background-position value. /// </summary> /// <param name="backgroundPosition">the background-position value</param> /// <param name="rectangle">the rectangle to position image in</param> /// <param name="imgSize">the size of the image</param> /// <returns>the top-left location</returns> static Point GetLocation(CssLength posX, CssLength posY, RectangleF rectangle, Size imgSize) { int left = (int)rectangle.Left; int top = (int)rectangle.Top; if (posX.IsBackgroundPositionName) { switch (posX.UnitOrNames) { case CssUnitOrNames.LEFT: { left = (int)(rectangle.Left + .5f); } break; case CssUnitOrNames.RIGHT: { left = (int)rectangle.Right - imgSize.Width; } break; } } else { //not complete ! left = (int)(rectangle.Left + (rectangle.Width - imgSize.Width) / 2 + .5f); } if (posY.IsBackgroundPositionName) { switch (posY.UnitOrNames) { case CssUnitOrNames.TOP: { top = (int)rectangle.Top; } break; case CssUnitOrNames.BOTTOM: { top = (int)rectangle.Bottom - imgSize.Height; } break; } } else { //not complete ! top = (int)(rectangle.Top + (rectangle.Height - imgSize.Height) / 2 + .5f); } return new Point(left, top); }