private double GetDecoratedCharWidth(FormattedText ft, List<CharacterDecorationInfo> decorationList, int index, out double charLeft, out double hCenter) { charLeft = 0; double width = ft.GetFullWidth(); hCenter = width / 2; double charWidth = width; var lhList = from d in decorationList where d.Position == Position.TopLeft select d; var rhList = from d in decorationList where d.Position == Position.TopRight select d; var topList = from d in decorationList where d.Position == Position.Top select d; var bottomList = from d in decorationList where d.Position == Position.Bottom select d; //var vList = from d in decorationList where d.Position == Position.Top || d.Position == Position.Bottom select d; var oList = from d in decorationList where d.Position == Position.Over select d; string text = ""; foreach (var v in lhList) { text += v.UnicodeString; } if (text.Length > 0) { var t = textManager.GetFormattedText(text, textManager.GetFormatIdForNewStyle(formats[index], FontStyles.Normal)); width += t.GetFullWidth(); charLeft = t.GetFullWidth(); hCenter += charLeft; } foreach (var v in topList) { var f = textManager.GetFormattedText("f", formats[index]); var fTop = f.TopExtra(); var ftTop = ft.TopExtra(); if (fTop < ftTop) { var t = textManager.GetFormattedText(v.UnicodeString, formats[index]); double diff = t.GetFullWidth() - charWidth; if (diff > 0) { charWidth += diff; charLeft += diff / 2; hCenter += diff / 2; } } } foreach (var v in bottomList) { var t = textManager.GetFormattedText(v.UnicodeString, formats[index]); double diff = t.GetFullWidth() - charWidth; if (diff > 0) { charWidth += diff; charLeft += diff / 2; hCenter += diff / 2; } } width = Math.Max(width, charWidth); foreach (var v in oList) { if (v.DecorationType == CharacterDecorationType.Cross || v.DecorationType == CharacterDecorationType.DoubleStrikeThrough || v.DecorationType == CharacterDecorationType.LeftCross || v.DecorationType == CharacterDecorationType.RightCross || v.DecorationType == CharacterDecorationType.StrikeThrough) { double diff = (ft.GetFullWidth() + FontSize * .1) - width; if (diff > 0) { width = ft.GetFullWidth() + FontSize * .1; charLeft += diff / 2; hCenter += diff / 2; } } } text = ""; foreach (var v in rhList) { text += v.UnicodeString; } if (text.Length > 0) { var t = textManager.GetFormattedText(text, formats[index]); width += t.GetFullWidth(); } return width; }
private void DrawAllDecorations(DrawingContext dc, double left, double hCenter, double top, double charLeft, FormattedText charFt, int index, List<CharacterDecorationInfo> decorationList) { DrawRightDecorations(dc, decorationList, top, left + charLeft + charFt.GetFullWidth(), formats[index]); DrawLeftDecorations(dc, decorationList, top, left + charLeft, formats[index]); DrawFaceDecorations(dc, charFt, decorationList, top, left + hCenter); DrawTopDecorations(dc, charFt, decorationList, top, left + hCenter, formats[index]); DrawBottomDecorations(dc, charFt, decorationList, top, left + hCenter, formats[index]); }
//index = index of the decorated character in this.textData private void DrawFaceDecorations(DrawingContext dc, FormattedText charText, List<CharacterDecorationInfo> cdiList, double top, double hCenter) { var decorations = (from x in cdiList where x.Position == Position.Over select x).ToList(); if (decorations.Count > 0) { double offset = 0; top += charText.Height + charText.OverhangAfter - charText.Extent; //ft.Baseline - ft.Extent + descent; double bottom = top + charText.Extent; //charText.Height - charText.Baseline + charText.OverhangAfter; double vCenter = top + charText.Extent / 2; double left = hCenter - charText.GetFullWidth() / 2 - offset; double right = hCenter + charText.GetFullWidth() / 2 + offset; Pen pen = PenManager.GetPen(FontSize * .035); foreach (var d in decorations) { switch (d.DecorationType) { case CharacterDecorationType.Cross: dc.DrawLine(pen, new Point(left, top), new Point(right, bottom)); dc.DrawLine(pen, new Point(left, bottom), new Point(right, top)); break; case CharacterDecorationType.LeftCross: dc.DrawLine(pen, new Point(left, top), new Point(right, bottom)); break; case CharacterDecorationType.RightCross: dc.DrawLine(pen, new Point(left, bottom), new Point(right, top)); break; case CharacterDecorationType.LeftUprightCross: dc.DrawLine(pen, new Point(hCenter - FontSize * .08, top - FontSize * 0.04), new Point(hCenter + FontSize * .08, bottom + FontSize * 0.04)); break; case CharacterDecorationType.RightUprightCross: dc.DrawLine(pen, new Point(hCenter + FontSize * .08, top - FontSize * 0.04), new Point(hCenter - FontSize * .08, bottom + FontSize * 0.04)); break; case CharacterDecorationType.StrikeThrough: dc.DrawLine(pen, new Point(left, vCenter), new Point(right, vCenter)); break; case CharacterDecorationType.DoubleStrikeThrough: dc.DrawLine(pen, new Point(left, vCenter - FontSize * .05), new Point(right, vCenter - FontSize * .05)); dc.DrawLine(pen, new Point(left, vCenter + FontSize * .05), new Point(right, vCenter + FontSize * .05)); break; case CharacterDecorationType.VStrikeThrough: dc.DrawLine(pen, new Point(hCenter, top - FontSize * .05), new Point(hCenter, bottom + FontSize * .05)); break; case CharacterDecorationType.VDoubleStrikeThrough: dc.DrawLine(pen, new Point(hCenter - FontSize * .05, top - FontSize * .05), new Point(hCenter - FontSize * .05, bottom + FontSize * .05)); dc.DrawLine(pen, new Point(hCenter + FontSize * .05, top - FontSize * .05), new Point(hCenter + FontSize * .05, bottom + FontSize * .05)); break; } } } }
protected void ReformatSign() { formattedText = FontFactory.GetFormattedText(Text, FontType, FontSize * FontSizeFactor, FontWeight); Width = formattedText.GetFullWidth() + LeftMarginFactor * FontSize + RightMarginFactor * FontSize; // * WidthFactor; Height = formattedText.Extent; }