private static TextOutline LeftAlign(TextOutline outline) { var center = outline.GetCenter(); var first = outline.GetFirstGlyphCenter(); return(outline.Translate(center.X - first.X, center.Y - first.Y)); }
public void AlignToLeft() { TextOutline outline = new TextOutline("Cl", font, emSize); AtomSymbol symbol = new AtomSymbol(outline, Array.Empty <TextOutline>()); AssertCloseTo(outline.GetFirstGlyphCenter(), symbol.AlignTo(Left).GetAlignmentCenter(), 0.01); }
/// <summary> /// Generate an annotation 'label' for an atom (located at 'basePoint'). The label is offset from /// the basePoint by the provided 'distance' and 'direction'. /// </summary> /// <param name="basePoint">the relative (0,0) reference</param> /// <param name="label">the annotation text</param> /// <param name="direction">the direction along which the label is laid out</param> /// <param name="distance">the distance along the direct to travel</param> /// <param name="scale">the font scale of the label</param> /// <param name="font">the font to use</param> /// <param name="symbol">the atom symbol to avoid overlap with</param> /// <returns>the position text outline for the annotation</returns> internal static TextOutline GenerateAnnotation(Vector2 basePoint, string label, Vector2 direction, double distance, double scale, Typeface font, double emSize, AtomSymbol symbol) { var italicHint = label.StartsWith(ItalicDisplayPrefix); label = italicHint ? label.Substring(ItalicDisplayPrefix.Length) : label; var annFont = italicHint ? new Typeface(font.FontFamily, WPF.FontStyles.Italic, font.Weight, font.Stretch) : font; var annOutline = new TextOutline(label, annFont, emSize).Resize(scale, -scale); // align to the first or last character of the annotation depending on the direction var center = direction.X > 0.3 ? annOutline.GetFirstGlyphCenter() : direction.X < -0.3 ? annOutline.GetLastGlyphCenter() : annOutline.GetCenter(); // Avoid atom symbol if (symbol != null) { var intersect = symbol.GetConvexHull().Intersect(VecmathUtil.ToPoint(basePoint), VecmathUtil.ToPoint(VecmathUtil.Sum(basePoint, direction))); // intersect should never be null be check against this if (intersect != null) { basePoint = VecmathUtil.ToVector(intersect); } } direction *= distance; direction += basePoint; // move to position return(annOutline.Translate(direction.X - center.X, direction.Y - center.Y)); }
public void TestGetFirstGlyphCenter() { TextOutline original = new TextOutline("Cl", font, emSize); var oCenter = original.GetCenter(); var tCenter = original.GetFirstGlyphCenter(); Assert.IsTrue(tCenter.X < oCenter.X); }
public void FirstAndLastCenterIsTheSameForSingleLetterOutline() { TextOutline oOutline = new TextOutline("O", font, emSize); var firstCenter = oOutline.GetFirstGlyphCenter(); var lastCenter = oOutline.GetLastGlyphCenter(); Assert.AreEqual(lastCenter.X, firstCenter.X, 0.01); Assert.AreEqual(lastCenter.Y, firstCenter.Y, 0.01); }
/// <summary> /// Access the center point of the symbol. The center point is determined by /// the alignment. /// </summary> /// <returns>center point</returns> public Point GetAlignmentCenter() { if (alignment == SymbolAlignment.Left) { return(element.GetFirstGlyphCenter()); } else if (alignment == SymbolAlignment.Right) { return(element.GetLastGlyphCenter()); } else { return(element.GetCenter()); } }