public PdfExportHelper(AllCaptionsRetValue allCaptions, Font captionFont, float documentWidthinMillimeters = DocumentWidthinMillimetersDefault) { _captions = allCaptions.Captions.ToArray(); _bandLinesAmount = allCaptions.RecursionDepth; _font = captionFont; DocumentWidthinMillimeters = documentWidthinMillimeters; ShouldCaptionBeWordWrapped = false; using (Bitmap bmpTemp = new Bitmap(1, 1)) { using (Graphics g = Graphics.FromImage(bmpTemp)) { g.PageUnit = GraphicsUnit.Millimeter; float totalWidth = 0.0f; for (int i = 0; i < _captions.Length; ++i) { totalWidth += g.MeasureString(_captions[i], captionFont).Width; totalWidth += ColumnIndentinMillimeters; if (totalWidth > DocumentWidthinMillimeters) { /* There is not enough space for all column captions. * Let's check if word wrapping can help. */ ShouldCaptionBeWordWrapped = CanWordWrappingHelp( _captions, captionFont, g, bmpTemp); break; } } HeaderHieghtInPixels = (int)CalculateHeaderHeight(_captions, g); } } }
private static AllCaptionsRetValue SelectAllCaptionsRecursively(BaseBand obj, int currentDepth, int maxDepth) { if (maxDepth < currentDepth) { maxDepth = currentDepth; } AllCaptionsRetValue retValue = new AllCaptionsRetValue(); retValue.RecursionDepth = maxDepth; for (int i = 0; i < obj.Columns.Count; ++i) { if (!obj.Columns[i].IsToDelete) { retValue.Captions.Add(new CaptionString( PreProcessString(obj.Columns[i].DisplayText), obj.Columns[i].IsRowArea, obj.Columns[i].UniquePath)); } } for (int i = 0; i < obj.Bands.Count; ++i) { if (!obj.Bands[i].IsToDelete) { AllCaptionsRetValue captions = SelectAllCaptionsRecursively(obj.Bands[i], currentDepth + 1, maxDepth); if (captions.Captions.Count > 0) { retValue.Captions.AddRange(captions.Captions); } if (retValue.RecursionDepth < captions.RecursionDepth) { retValue.RecursionDepth = captions.RecursionDepth; } } } return(retValue); }