Exemplo n.º 1
0
        public void ReversingFormatPOOHOEt()
        {
            List <string> tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("PO(OH)OEt", tokens));
            AbbreviationLabel.Reverse(tokens);
            AbbreviationLabel.Format(tokens);
            Assert.AreEqual("EtO(HO)OP", string.Join("", tokens));
        }
Exemplo n.º 2
0
        public void FormatTBu()
        {
            var tokens = new[] { "tBu" };
            List <AbbreviationLabel.FormattedText> texts = AbbreviationLabel.Format(tokens);

            Assert.AreEqual(2, texts.Count);
            Assert.AreEqual("t", texts[0].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_ITALIC, texts[0].Style);
            Assert.AreEqual("Bu", texts[1].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_NORMAL, texts[1].Style);
        }
Exemplo n.º 3
0
        public void FormatFeacac3()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("Fe(acac)3", tokens));
            List <AbbreviationLabel.FormattedText> formatted = AbbreviationLabel.Format(tokens);

            Assert.AreEqual("Fe(acac)", formatted[0].Text);
            Assert.AreEqual(0, formatted[0].Style);
            Assert.AreEqual("3", formatted[1].Text);
            Assert.AreEqual(-1, formatted[1].Style);
        }
Exemplo n.º 4
0
        public void FormatOPO3()
        {
            var tokens = new[] { "O", "P", "O3", "-2" };
            var texts  = AbbreviationLabel.Format(tokens);

            Assert.AreEqual(3, texts.Count);
            Assert.AreEqual("OPO", texts[0].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_NORMAL, texts[0].Style);
            Assert.AreEqual("3", texts[1].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_SUBSCRIPT, texts[1].Style);
            Assert.AreEqual("2−", texts[2].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_SUPSCRIPT, texts[2].Style);
        }
Exemplo n.º 5
0
        public void FormatOPO3H2()
        {
            var tokens = new[] { "O", "P", "O3", "H2" };
            List <AbbreviationLabel.FormattedText> texts = AbbreviationLabel.Format(tokens);

            Assert.AreEqual(4, texts.Count);
            Assert.AreEqual("OPO", texts[0].Text);
            Assert.AreEqual(0, texts[0].Style);
            Assert.AreEqual("3", texts[1].Text);
            Assert.AreEqual(-1, texts[1].Style);
            Assert.AreEqual("H", texts[2].Text);
            Assert.AreEqual(0, texts[2].Style);
            Assert.AreEqual("2", texts[3].Text);
            Assert.AreEqual(-1, texts[3].Style);
        }
Exemplo n.º 6
0
        public void FormatRubpy3Cl2()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("Ru(bpy)3Cl2", tokens));
            var formatted = AbbreviationLabel.Format(tokens);

            AbbreviationLabel.Reduce(formatted, 0, formatted.Count);
            Assert.AreEqual("Ru(bpy)", formatted[0].Text);
            Assert.AreEqual(0, formatted[0].Style);
            Assert.AreEqual("3", formatted[1].Text);
            Assert.AreEqual(-1, formatted[1].Style);
            Assert.AreEqual("Cl", formatted[2].Text);
            Assert.AreEqual(0, formatted[2].Style);
            Assert.AreEqual("2", formatted[3].Text);
            Assert.AreEqual(-1, formatted[3].Style);
        }
Exemplo n.º 7
0
        public void NEt3DotHCl()
        {
            List <string> tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("NEt3·HCl", tokens));
            Assert.AreEqual(5, tokens.Count);
            Assert.AreEqual("N", tokens[0]);
            Assert.AreEqual("Et3", tokens[1]);
            Assert.AreEqual("·", tokens[2]);
            Assert.AreEqual("H", tokens[3]);
            Assert.AreEqual("Cl", tokens[4]);
            List <AbbreviationLabel.FormattedText> formatted = AbbreviationLabel.Format(tokens);

            AbbreviationLabel.Reduce(formatted, 0, formatted.Count);
            Assert.AreEqual(3, formatted.Count);
            Assert.AreEqual("NEt", formatted[0].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_NORMAL, formatted[0].Style);
            Assert.AreEqual("3", formatted[1].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_SUBSCRIPT, formatted[1].Style);
            Assert.AreEqual("·HCl", formatted[2].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_NORMAL, formatted[2].Style);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Generate a formatted abbreviation AtomSymbol for the given Hydrogen position.
        /// </summary>
        /// <param name="tokens">the parsed tokens</param>
        /// <param name="position">hydrogen position - determines if we reverse the label</param>
        /// <returns>the generated symbol</returns>
        public AtomSymbol GenerateAbbreviationSymbol(List <string> tokens, HydrogenPosition position)
        {
            if (position == HydrogenPosition.Left)
            {
                AbbreviationLabel.Reverse(tokens);
            }

            var tmpRefPoint = new TextOutline("H", font, emSize);
            var fTexts      = AbbreviationLabel.Format(tokens);

            var italicFont = new Typeface(font.FontFamily, FontStyles.Italic, font.Weight, font.Stretch);

            var outlines = new List <TextOutline>(fTexts.Count);

            foreach (var fText in fTexts)
            {
                var outline = fText.Style == AbbreviationLabel.STYLE_ITALIC
                            ? new TextOutline(fText.Text, italicFont, emSize)
                            : new TextOutline(fText.Text, font, emSize);

                // resize and position scripts
                if (fText.Style == AbbreviationLabel.STYLE_SUBSCRIPT)
                {
                    outline = outline.Resize(scriptSize, scriptSize);
                    outline = PositionSubscript(tmpRefPoint, outline);
                }
                else if (fText.Style == AbbreviationLabel.STYLE_SUPSCRIPT)
                {
                    outline = outline.Resize(scriptSize, scriptSize);
                    outline = PositionSuperscript(tmpRefPoint, outline);
                }

                outlines.Add(outline);
            }

            // position the outlines relative to each other
            for (int i = 1; i < outlines.Count; i++)
            {
                var ref_ = outlines[i - 1];
                var curr = outlines[i];
                // charge aligns to symbol not a subscript part
                if (fTexts[i].Style == AbbreviationLabel.STYLE_SUPSCRIPT &&
                    fTexts[i - 1].Style == AbbreviationLabel.STYLE_SUBSCRIPT && i > 1)
                {
                    ref_ = outlines[i - 2];
                }
                outlines[i] = PositionAfter(ref_, curr);
            }

            // find symbol where we want to attach the bond
            // this becomes the primary outline
            int index;

            if (position == HydrogenPosition.Left)
            {
                for (index = outlines.Count - 1; index >= 0; index--)
                {
                    if ((fTexts[index].Style & 0x1) == 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                for (index = 0; index < outlines.Count; index++)
                {
                    if ((fTexts[index].Style & 0x1) == 0)
                    {
                        break;
                    }
                }
            }
            var primary = outlines[index];

            outlines.RemoveAt(index);

            return(new AtomSymbol(primary, outlines));
        }