/** * private ctor used for fit'ing */ private HorizontalArea(Area[] content, Area source) : base(content, source) { // calulate bounding box BoundingBox box = BoundingBox.New(); foreach (Area a in content) { box.Append(a.BoundingBox); } this.box = box; }
public override AreaRegion GetEditRegion(IFormattingContext context, float x, float y, int index) { // measure horizontal position of char: BoundingBox horz = BoundingBox.New(); float left, right; for (int i = 0; i < index && i < content.Length; i++) { BoundingBox tmp = BoundingBox.New(); context.MeasureGlyph(font, content[i], out tmp, out left, out right); horz.Append(tmp); } return(new AreaRegion(this, x + horz.Width, y)); }
/** * create a string area */ public StringArea(IFormattingContext context, string content) { this.font = context.GetFont(); this.content = content; box = BoundingBox.New(); float left = 0, right = 0; for(int i = 0; i < content.Length; i++) { BoundingBox tmp = BoundingBox.New(); context.MeasureGlyph(font, content[i], out tmp, out left, out right); box.Append(tmp); // left edge of first char if(i == 0) { leftEdge = left; } } // right edge of last char rightEdge = right; }
/** * create a string area */ public StringArea(IFormattingContext context, string content) { this.font = context.GetFont(); this.content = content; box = BoundingBox.New(); float left = 0, right = 0; for (int i = 0; i < content.Length; i++) { BoundingBox tmp = BoundingBox.New(); context.MeasureGlyph(font, content[i], out tmp, out left, out right); box.Append(tmp); // left edge of first char if (i == 0) { leftEdge = left; } } // right edge of last char rightEdge = right; }
object MathML.MathMLVisitor.Visit(MathMLPresentationContainer e, object args) { IFormattingContext context = ((IFormattingContext)args).Clone(); MathMLNodeList arguments = e.Arguments; BoundingBox extent = BoundingBox.New(); int stretchCount = 0; // save the stretch size because stretch scope can not extend into another // level of nesting BoundingBox stretch = context.Stretch; context.Stretch = BoundingBox.New(); // process all nodes that are not stretchy operators, get thier total // extents for (int i = 0; i < arguments.Count; i++) { MathMLElement element = (MathMLElement)arguments[i]; MathMLOperatorElement op = element as MathMLOperatorElement; if (op == null || op.Stretchy == false) { //areas[i] = (Area)element.Accept(this, context); extent.Append((BoundingBox)element.Accept(this, context)); } if (op != null && op.Stretchy) { stretchCount++; } } // if we have any elements that can be stretched, stretch them if (stretchCount > 0) { if (!stretch.Defined) { // avail width is epsilon because stretchy glyphs were not counted in the // width calculation context.Stretch = BoundingBox.New(Single.Epsilon, extent.Height, extent.Depth); } else { // set the stretch size back to stretch the child elements context.Stretch = stretch; // calculate availible width context.StretchWidth = context.StretchWidth - extent.Width; if (context.Stretch.Width < 0) { context.StretchWidth = 0; } // size to stretch each width equally context.StretchWidth = context.Stretch.Width / (float)stretchCount; } // process all areas that need to be stretched for (int i = 0; i < arguments.Count; i++) { MathMLOperatorElement op = arguments[i] as MathMLOperatorElement; if (op != null && op.Stretchy) { //areas[i] = (Area)op.Accept(this, context); extent.Append((BoundingBox)op.Accept(this, context)); } } } return(extent); }
private static void CreateCellSizesAndShifts(MathMLTableCellElement[][] cells, Row[] rows, Column[] columns, ref BoundingBox[][] sizes, ref PointF[][] shifts) { sizes = new BoundingBox[cells.Length][]; shifts = new PointF[cells.Length][]; // init to 1 to skip over first spacing row for frame int rowIndex = 1; // y shift, start with upper frame space float y = rows[0].VerticalExtent; // outer loop - rows for (int i = 0; i < cells.Length; i++) { // init to 1 to skip over first spacing column for frame int colIndex = 1; // start x shift with frame space float x = columns[0].Width; sizes[i] = new BoundingBox[cells[i].Length]; shifts[i] = new PointF[cells[i].Length]; // inner loop - columns for (int j = 0; j < cells[i].Length; j++) { if (cells[i][j] != null) { BoundingBox box = BoundingBox.New(); for (int k = 0, k2 = 0; k < cells[i][j].ColumnSpan; k++, k2 += 2) { if (colIndex + k2 < columns.Length) { if (k2 == 0) { box.Width = columns[colIndex].Width; } else { // add content column box.Append(BoundingBox.New(columns[colIndex + k].Width, 0, 0)); // add space column box.Append(BoundingBox.New(columns[colIndex + k + 1].Width, 0, 0)); } } else { Debug.WriteLine("warning, insuffcient columns for spanning"); } } for (int k = 0, k2 = 0; k < cells[i][j].RowSpan; k++, k2 += 2) { if (rowIndex + k2 < rows.Length) { if (k2 == 0) { box.Height = rows[rowIndex].Height; box.Depth = rows[rowIndex].Depth; } else { // add content row box.Over(BoundingBox.New(0, rows[rowIndex + k2].Height, rows[rowIndex + k].Depth)); // add space row box.Over(BoundingBox.New(0, rows[rowIndex + k2 + 1].Height, rows[rowIndex + k + 1].Depth)); } } } Debug.Assert(box.Height == rows[rowIndex].Height); sizes[i][j] = box; shifts[i][j] = new PointF(x, y + box.Height); } // add width of current column and next column which is a spaceing column // and set index to next non space column x += columns[colIndex++].Width; x += columns[colIndex++].Width; } // add vertical extent of current row and next row which is a spaceing row // and set index to next non space row y += rows[rowIndex++].VerticalExtent; y += rows[rowIndex++].VerticalExtent; } }