public PointF Size(Graphics pGraphics) { EspackPrintingText _textObj = new EspackPrintingText(string.Format(Format, Counter, Total), Font); _textObj.Graphics = pGraphics; return(_textObj.Size); }
// Convert all relative positions to absolute public void ArrangeItems(Graphics pGraphics, PointF HardMargins, EspackPrintingArea pPreviousArea) { if (pPreviousArea != null) { bool _setCoords = true; if (Docking != EnumZoneDocking.NONE) { switch (pPreviousArea.Docking) { case EnumZoneDocking.RIGHTWARDS: if (X == -1) { X = pPreviousArea.X + pPreviousArea.Width + 2; } if (Y == -1) { Y = pPreviousArea.Y; } _setCoords = false; break; case EnumZoneDocking.DOWNWARDS: if (X == -1) { X = pPreviousArea.X; } if (Y == -1) { Y = pPreviousArea.Y + pPreviousArea.Height; } _setCoords = false; break; } } if (_setCoords) { if (X == -1) { X = HardMargins.X; } if (Y == -1) { Y = pPreviousArea.Y + pPreviousArea.Height; } } if (Font == null) { Font = pPreviousArea.Font; } } else { // Set the min visible coordinates as default if (X == -1) { X = HardMargins.X; } if (Y == -1) { Y = HardMargins.Y; } Font = Font ?? new EspackFont(); } // Calculate the X and Y for each item when they are not defined IEspackPrintingItem _previousItem = null; EspackPrintingText _previousText = null; Brush _previousBrush = null; Pen _previousPen = null; foreach (var _item in Items) { // Cast _item as IEspackPrintingItem var _currentItem = (IEspackPrintingItem)_item; _currentItem.Graphics = pGraphics; // If not ready to be printed, it needs to be arranged if (!_currentItem.PrintMe) { if (_currentItem.GetType().Name != "EspackPrintingDrawing") { if (_previousItem != null) { // Previous item exists if (_currentItem.X == -1 && _currentItem.Y == -1) { // X and Y not set. Set them depending of EOL value if (!_previousItem.EOL) { _currentItem.X = _previousItem.X + _previousItem.Width; _currentItem.Y = _previousItem.Y; } else { if (Zone == EnumDocumentZones.BODY && _previousItem.Y + _previousItem.Height > MaxHeight) { break; } _currentItem.X = X; // LEFT MARGIN _currentItem.Y = _previousItem.Y + _previousItem.Height; } } } else { // First element: set defaults if not passed _currentItem.X = _currentItem.X == -1 ? X : X + _currentItem.X; // LEFT MARGIN _currentItem.Y = _currentItem.Y == -1 ? Y : Y + _currentItem.Y; // TOP MARGIN } // Only for text objects if (_currentItem.GetType().Name == "EspackPrintingText") { // Cast it to EspackPrintingText using (var _currentText = (EspackPrintingText)_currentItem) { if (_previousText != null) { // Not the first text object if (_currentText.Font == null) { // Get the font from the previous object if set Font _f = _previousText.Font ?? (Font)Font.Font.Clone(); // Disable the auto bold when the previous text was bold-forced and current is not a title if ((_previousText.ForcedBold || _previousText.ForcedUnderline) && !_currentText.Title) { _f = new Font(_f.Name, _f.Size, _f.Style & (_previousText.ForcedBold?~FontStyle.Bold: _f.Style) & (_previousText.ForcedUnderline && Zone == EnumDocumentZones.BODY ? ~FontStyle.Underline : _f.Style)); } // Set current font _currentText.Font = _f; } // Set current brush if (_currentText.Brush == null) { _currentText.Brush = _previousBrush ?? (Brush)Font.Brush.Clone(); } } else { // First text object: set font / brush _currentText.Font = _currentText.Font ?? (Font)Font.Font.Clone(); _currentText.Brush = _currentText.Brush ?? (Brush)Font.Brush.Clone(); } // Force bold if current text is a title (and font was not bold) if (_currentText.Title && !(_currentText.Font.Bold && _currentText.Font.Underline)) { _currentText.ForcedBold = !_currentText.Font.Bold; if (Zone == EnumDocumentZones.BODY) { _currentText.ForcedUnderline = !_currentText.Font.Underline; } _currentText.Font = new Font(_currentText.Font.Name, _currentText.Font.SizeInPoints, _currentText.Font.Style | FontStyle.Bold | (Zone == EnumDocumentZones.BODY?FontStyle.Underline:0)); } _previousText = _currentText; _previousBrush = _currentText.Brush; } } // Calculate the Height / Width of current area if (_currentItem.X - X + _currentItem.Width > Width) { Width = _currentItem.X - X + _currentItem.Width; } if (_currentItem.Y - Y + _currentItem.Height > Height) { Height = _currentItem.Y - Y + _currentItem.Height; } } // Only for drawing objects (totally independent to the area) else if (_currentItem.GetType().Name == "EspackPrintingDrawing") { if (((EspackPrintingDrawing)_currentItem).Pen == null) { ((EspackPrintingDrawing)_currentItem).Pen = _previousPen ?? (Pen)Pen.Clone(); ((EspackPrintingDrawing)_currentItem).Pen.Brush = _previousBrush ?? (Brush)Font.Brush.Clone(); } _previousBrush = ((EspackPrintingDrawing)_currentItem).Pen.Brush; _previousPen = ((EspackPrintingDrawing)_currentItem).Pen; } // Set current item as ready to be printed _currentItem.PrintMe = true; } _previousItem = _currentItem; } }