public Size MeasureCell(MapGraphics g, int fontSizeReducedBy, Font legendAutoFont, Size singleWCharacterSize) { if (this.cachedCellSizeFontReducedBy == fontSizeReducedBy && !this.cachedCellSize.IsEmpty) { return(this.cachedCellSize); } Size result = Size.Empty; bool flag = false; Font cellFont = this.GetCellFont(legendAutoFont, fontSizeReducedBy, out flag); if (this.CellType == LegendCellType.Symbol) { result.Width = (int)((float)(Math.Abs(this.SymbolSize.Width) * singleWCharacterSize.Width) / 100.0); result.Height = (int)((float)(Math.Abs(this.SymbolSize.Height) * singleWCharacterSize.Height) / 100.0); result.Width = (int)Math.Round((double)result.Width * 1.1); result.Height = (int)Math.Round((double)result.Height * 1.25); goto IL_01dd; } if (this.CellType == LegendCellType.Image) { if (this.ImageSize.IsEmpty && !string.IsNullOrEmpty(this.Image)) { Image image = this.GetLegend().Common.ImageLoader.LoadImage(this.Image); result.Width = image.Width; result.Height = image.Height; } else { result.Width = (int)((float)(Math.Abs(this.ImageSize.Width) * singleWCharacterSize.Width) / 100.0); result.Height = (int)((float)(Math.Abs(this.ImageSize.Height) * singleWCharacterSize.Height) / 100.0); } goto IL_01dd; } if (this.CellType == LegendCellType.Text) { string cellText = this.GetCellText(); result = g.MeasureStringAbs(cellText + "I", cellFont); goto IL_01dd; } throw new InvalidOperationException("Unknown Legend Cell Type: " + ((Enum)(object)this.CellType).ToString((IFormatProvider)CultureInfo.CurrentCulture)); IL_01dd: result.Width += (int)((float)((this.Margins.Left + this.Margins.Right) * singleWCharacterSize.Width) / 100.0); result.Height += (int)((float)((this.Margins.Top + this.Margins.Bottom) * singleWCharacterSize.Height) / 100.0); if (this.GetLegend() != null && this.legendItem != null && this.legendItem.Separator != 0) { result.Height += this.GetLegend().GetSeparatorSize(g, this.legendItem.Separator).Height; } if (flag) { cellFont.Dispose(); cellFont = null; } this.cachedCellSize = result; this.cachedCellSizeFontReducedBy = fontSizeReducedBy; return(result); }
internal Size MeasureCell(MapGraphics g, int fontSizeReducedBy, Font legendAutoFont, Size singleWCharacterSize) { if (cachedCellSizeFontReducedBy == fontSizeReducedBy && !cachedCellSize.IsEmpty) { return(cachedCellSize); } Size result = Size.Empty; bool disposeFont = false; Font cellFont = GetCellFont(legendAutoFont, fontSizeReducedBy, out disposeFont); if (CellType == LegendCellType.Symbol) { result.Width = (int)((float)(Math.Abs(SymbolSize.Width) * singleWCharacterSize.Width) / 100f); result.Height = (int)((float)(Math.Abs(SymbolSize.Height) * singleWCharacterSize.Height) / 100f); result.Width = (int)Math.Round((double)result.Width * 1.1); result.Height = (int)Math.Round((double)result.Height * 1.25); } else if (CellType == LegendCellType.Image) { if (ImageSize.IsEmpty && !string.IsNullOrEmpty(Image)) { Image image = GetLegend().Common.ImageLoader.LoadImage(Image); result.Width = image.Width; result.Height = image.Height; } else { result.Width = (int)((float)(Math.Abs(ImageSize.Width) * singleWCharacterSize.Width) / 100f); result.Height = (int)((float)(Math.Abs(ImageSize.Height) * singleWCharacterSize.Height) / 100f); } } else { if (CellType != 0) { throw new InvalidOperationException("Unknown Legend Cell Type: " + CellType.ToString(CultureInfo.CurrentCulture)); } string cellText = GetCellText(); result = g.MeasureStringAbs(cellText + "I", cellFont); } result.Width += (int)((float)((Margins.Left + Margins.Right) * singleWCharacterSize.Width) / 100f); result.Height += (int)((float)((Margins.Top + Margins.Bottom) * singleWCharacterSize.Height) / 100f); if (GetLegend() != null && legendItem != null && legendItem.Separator != 0) { result.Height += GetLegend().GetSeparatorSize(g, legendItem.Separator).Height; } if (disposeFont) { cellFont.Dispose(); cellFont = null; } cachedCellSize = result; cachedCellSizeFontReducedBy = fontSizeReducedBy; return(result); }
private void PaintCellText(MapGraphics g, int fontSizeReducedBy, Font legendAutoFont, Size singleWCharacterSize) { bool disposeFont = false; Font cellFont = GetCellFont(legendAutoFont, fontSizeReducedBy, out disposeFont); g.StartHotRegion(this); using (SolidBrush brush = new SolidBrush(GetCellTextColor())) { StringFormat stringFormat = new StringFormat(StringFormat.GenericDefault); stringFormat.FormatFlags = StringFormatFlags.LineLimit; stringFormat.Trimming = StringTrimming.EllipsisCharacter; stringFormat.Alignment = StringAlignment.Center; if (Alignment == ContentAlignment.BottomLeft || Alignment == ContentAlignment.MiddleLeft || Alignment == ContentAlignment.TopLeft) { stringFormat.Alignment = StringAlignment.Near; } else if (Alignment == ContentAlignment.BottomRight || Alignment == ContentAlignment.MiddleRight || Alignment == ContentAlignment.TopRight) { stringFormat.Alignment = StringAlignment.Far; } stringFormat.LineAlignment = StringAlignment.Center; if (Alignment == ContentAlignment.BottomCenter || Alignment == ContentAlignment.BottomLeft || Alignment == ContentAlignment.BottomRight) { stringFormat.LineAlignment = StringAlignment.Far; } else if (Alignment == ContentAlignment.TopCenter || Alignment == ContentAlignment.TopLeft || Alignment == ContentAlignment.TopRight) { stringFormat.LineAlignment = StringAlignment.Near; } SizeF sizeF = g.MeasureStringAbs(GetCellText(), cellFont, new SizeF(10000f, 10000f), stringFormat); if (sizeF.Height > (float)cellPosition.Height && (stringFormat.FormatFlags & StringFormatFlags.LineLimit) != 0) { stringFormat.FormatFlags ^= StringFormatFlags.LineLimit; } else if (sizeF.Height < (float)cellPosition.Height && (stringFormat.FormatFlags & StringFormatFlags.LineLimit) == 0) { stringFormat.FormatFlags |= StringFormatFlags.LineLimit; } g.DrawStringRel(GetCellText(), cellFont, brush, g.GetRelativeRectangle(cellPosition), stringFormat); } g.EndHotRegion(); if (disposeFont) { cellFont.Dispose(); cellFont = null; } }