private void DynamicFontSizeApply(Graphics graphics) { var minFontSize = 0; var maxFontSize = Height; int fontSize = Height / 2; while (minFontSize != maxFontSize) { var fontFamilyAttempt = new FontFamily(Font); var fontAttempt = new Font(fontFamilyAttempt, fontSize, FontStyle); var fontToolAttempt = new FontTool(graphics, fontAttempt, FontStyle, fontFamilyAttempt); var measurement = fontToolAttempt.Measure(Content); if (measurement.Width > Width || measurement.Height > Height) { maxFontSize = fontSize - 1; } else { minFontSize = fontSize; } fontSize = (int)(Math.Ceiling((decimal)(maxFontSize - minFontSize) / 2) + minFontSize); } var fontFamily = new FontFamily(Font); var font = new Font(fontFamily, fontSize, FontStyle); var fontTool = new FontTool(graphics, font, FontStyle, fontFamily); var backgroundTool = new BackgroundTool(graphics, BackgroundColor, BackgroundBorderColor, BackgroundBorderThickness); var textBlock = new TextBlock(Width, LineAlignment, WordAlignment, fontTool, backgroundTool); textBlock.Add(new CharacterSequence(Content, Color, OutlineColor, OutlineThickness, fontTool), fontTool, backgroundTool); Finalize(graphics, textBlock); }
public void Add(IDrawableSegment segment, FontTool fontTool, BackgroundTool backgroundTool) { if (_textLines.Last().Width + segment.Width > _maxWidth) { _spaces.Clear(); NewLine(fontTool, backgroundTool); _textLines.Last().Add(segment); } else { _textLines.Last().Add(_spaces); _spaces.Clear(); _textLines.Last().Add(segment); } }
public TextStyling(Graphics graphics, string fontName, int fontSize, FontStyle fontStyle, Color color, Color backgroundColor, Color backgroundBorderColor, int backgroundBorderThickness, Color outlineColor, int outlineThickness) { FontName = fontName; FontSize = fontSize; FontStyle = fontStyle; Color = color; BackgroundColor = backgroundColor; BackgroundBorderColor = backgroundBorderColor; BackgroundBorderThickness = backgroundBorderThickness; OutlineColor = outlineColor; OutlineThickness = outlineThickness; var fontFamily = new FontFamily(fontName); var font = new Font(fontFamily, FontSize, FontStyle); FontTool = new FontTool(graphics, font, fontStyle, fontFamily); BackgroundTool = new BackgroundTool(graphics, backgroundColor, backgroundBorderColor, backgroundBorderThickness); }
public TextSequence(VerticalAlignment wordAlignment, BackgroundTool backgroundTool, int minHeight = 0) { _wordAlignment = wordAlignment; _backgroundTool = backgroundTool; _minHeight = minHeight; }
public void NewLine(FontTool fontTool, BackgroundTool backgroundTool) => _textLines.Add(new TextSequence(_wordAlignment, backgroundTool, fontTool.LineHeight));
public TextBlock(int maxWidth, HorizontalAlignment lineAlignment, VerticalAlignment wordAlignment, FontTool fontTool, BackgroundTool backgroundTool) { _maxWidth = maxWidth; _lineAlignment = lineAlignment; _wordAlignment = wordAlignment; NewLine(fontTool, backgroundTool); }