public void ResizeMaintainsCenter() { TextOutline clOutline = new TextOutline("Cl", font, emSize); var orgCenter = clOutline.GetCenter(); var newCenter = clOutline.Resize(21, 5).GetCenter(); Assert.AreEqual(newCenter.X, orgCenter.X, 0.01); Assert.AreEqual(newCenter.Y, orgCenter.Y, 0.01); }
public void ResizeModifiesBounds() { TextOutline original = new TextOutline("Cl", font, emSize); TextOutline transformed = original.Resize(2, 2); var oBounds = original.GetBounds(); var tBounds = transformed.GetBounds(); Assert.AreEqual(oBounds.X - oBounds.Width / 2, tBounds.X, 0.01); Assert.AreEqual(oBounds.Y - oBounds.Height / 2, tBounds.Y, 0.01); Assert.AreEqual(oBounds.Width * 2, tBounds.Width, 0.01); Assert.AreEqual(oBounds.Height * 2, tBounds.Height, 0.01); }
public IRenderingElement Generate() { if (!delocalisedDonuts) { return(null); } var group = new ElementGroup(); smallest = Cycles.EdgeShort.Find(mol).ToRingSet(); foreach (var ring in smallest) { if (!CanDelocalise(ring)) { continue; } foreach (var bond in ring.Bonds) { bonds.Add(bond); } int charge = 0; int unpaired = 0; foreach (var atom in ring.Atoms) { var q = atom.FormalCharge ?? 0; if (q == 0) { continue; } int nCyclic = 0; foreach (var bond in mol.GetConnectedBonds(atom)) { if (bond.IsInRing) { nCyclic++; } } if (nCyclic > 2) { continue; } atoms.Add(atom); charge += q; } var p2 = GeometryUtil.Get2DCenter(ring); if (charge != 0) { var qText = charge < 0 ? "–" : "+"; if (charge < -1) { qText = Math.Abs(charge) + qText; } else if (charge > +1) { qText = Math.Abs(charge) + qText; } TextOutline qSym = new TextOutline(qText, font, emSize); qSym = qSym.Resize(1 / scale, -1 / scale); qSym = qSym.Translate(p2.X - qSym.GetCenter().X, p2.Y - qSym.GetCenter().Y); group.Add(GeneralPath.ShapeOf(qSym.GetOutline(), fgColor)); } double s = GeometryUtil.GetBondLengthMedian(ring); double n = ring.Bonds.Count; double r = s / (2 * Math.Tan(Math.PI / n)); group.Add(new OvalElement(new WPF::Point(p2.X, p2.Y), r - 1.5 * dbSpacing, stroke, false, fgColor)); } return(group); }
/// <summary> /// Generates an atom symbol for a pseudo atom. /// </summary> /// <returns>the atom symbol</returns> public AtomSymbol GeneratePseudoSymbol(string label, HydrogenPosition position) { var italicFont = new Typeface(font.FontFamily, FontStyles.Italic, FontWeights.Bold, font.Stretch); var outlines = new List <TextOutline>(3); int beg = 0; int pos = 0; int len = label.Length; // upper case followed by lower case while (pos < len && IsUpperCase(label[pos])) { pos++; } if (label[0] != 'R') // Ar is not A^r but 'Ra' is R^a etc { while (pos < len && IsLowerCase(label[pos])) { pos++; } } if (pos > beg) { outlines.Add(new TextOutline(label.Substring(beg, pos), italicFont, emSize)); beg = pos; // 2a etc. while (pos < len && IsDigit(label[pos])) { pos++; } while (pos < len && IsLowerCase(label[pos])) { pos++; } if (pos > beg) { var outline = new TextOutline(label.Substring(beg, pos - beg), italicFont, emSize); outline = outline.Resize(scriptSize, scriptSize); outline = PositionSuperscript(outlines[0], outline); outlines.Add(outline); } int numPrimes = 0; while (pos < len) { switch (label[pos]) { case '\'': numPrimes++; break; case '`': numPrimes++; break; case '‘': numPrimes++; break; case '’': numPrimes++; break; case '‛': numPrimes++; break; case '“': numPrimes += 2; break; case '”': numPrimes += 2; break; case '′': numPrimes++; break; case '″': numPrimes += 2; break; case '‴': numPrimes += 3; break; case '⁗': numPrimes += 4; break; case '‵': numPrimes++; break; case '‶': numPrimes += 2; break; case '‷': numPrimes += 3; break; case '´': numPrimes++; break; case 'ˊ': numPrimes++; break; case '́': numPrimes++; break; case '˝': numPrimes += 2; break; case '̋': numPrimes += 2; break; default: goto break_PRIMES; } pos++; } break_PRIMES: if (pos < len) { return(new AtomSymbol( new TextOutline(label, italicFont, emSize), Array.Empty <TextOutline>())); } else { TextOutline outline = null; var ref_ = outlines[outlines.Count - 1]; switch (numPrimes) { case 0: break; case 1: outline = new TextOutline("′", font, emSize); break; case 2: outline = new TextOutline("″", font, emSize); break; case 3: outline = new TextOutline("‴", font, emSize); break; default: string lab = ""; while (numPrimes-- > 0) { lab += "′"; } outline = new TextOutline(lab, font, emSize); break; } if (outline != null) { if (outlines.Count > 1) { outline = outline.Resize(scriptSize, scriptSize); } outline = PositionSuperscript(ref_, outline); outlines.Add(outline); } } // line up text for (int i = 1; i < outlines.Count; i++) { var ref_ = outlines[i - 1]; var curr = outlines[i]; outlines[i] = PositionAfter(ref_, curr); } return(new AtomSymbol(outlines[0], outlines.GetRange(1, outlines.Count - 1))); } else { return(new AtomSymbol(new TextOutline(label, italicFont, emSize), Array.Empty <TextOutline>())); } }