예제 #1
0
 public void CopyTo(StyleAttributes styleAttributes)
 {
     styleAttributes.displayStyle   = this.displayStyle;
     styleAttributes.scriptLevel    = this.scriptLevel;
     styleAttributes.canOverride    = this.canOverride;
     styleAttributes.color          = this.color;
     styleAttributes.background     = this.background;
     styleAttributes.size           = this.size;
     styleAttributes.scale          = this.scale;
     styleAttributes.isBold         = this.isBold;
     styleAttributes.isItalic       = this.isItalic;
     styleAttributes.isNormal       = this.isNormal;
     styleAttributes.isUnderline    = this.isUnderline;
     styleAttributes.isTop          = this.isTop;
     styleAttributes.isDoubleStruck = this.isDoubleStruck;
     styleAttributes.isFractur      = this.isFractur;
     styleAttributes.isScript       = this.isScript;
     styleAttributes.isSans         = this.isSans;
     styleAttributes.isMonospace    = this.isMonospace;
     styleAttributes.styleClass     = this.styleClass;
     styleAttributes.hasColor       = this.hasColor;
     styleAttributes.hasBackground  = this.hasBackground;
     styleAttributes.hasSize        = this.hasSize;
     styleAttributes.fontFamily     = this.fontFamily;
 }
예제 #2
0
 public void CopyTo(StyleAttributes styleAttributes)
 {
     styleAttributes.displayStyle = this.displayStyle;
     styleAttributes.scriptLevel = this.scriptLevel;
     styleAttributes.canOverride = this.canOverride;
     styleAttributes.color = this.color;
     styleAttributes.background = this.background;
     styleAttributes.size = this.size;
     styleAttributes.scale = this.scale;
     styleAttributes.isBold = this.isBold;
     styleAttributes.isItalic = this.isItalic;
     styleAttributes.isNormal = this.isNormal;
     styleAttributes.isUnderline = this.isUnderline;
     styleAttributes.isTop = this.isTop;
     styleAttributes.isDoubleStruck = this.isDoubleStruck;
     styleAttributes.isFractur = this.isFractur;
     styleAttributes.isScript = this.isScript;
     styleAttributes.isSans = this.isSans;
     styleAttributes.isMonospace = this.isMonospace;
     styleAttributes.styleClass = this.styleClass;
     styleAttributes.hasColor = this.hasColor;
     styleAttributes.hasBackground = this.hasBackground;
     styleAttributes.hasSize = this.hasSize;
     styleAttributes.fontFamily = this.fontFamily;
     
 }
예제 #3
0
 public Node(StyleAttributes styleAttributes)
 {
     firstChild = null;
     lastChild = null;
     nextSibling = null;
     prevSibling = null;
     parent_ = null;
     upperNode = null;
     lowerNode = null;
     glyph = null;
     namespaceURI = "";
     isVisible = true;
     isGlyph = false;
     skip = false;
     literalCaret = 0;
     literalStart = 0;
     isAppend = false;
     fontFamily = "";
     tokenType = Tokens.ID;
     yOffset = 0;
     displayStyle = false;
     scriptLevel_ = 0;
     style_ = null;
     literalText = "";
     type_ = null;
     attrs = null;
     tagDeleted = false;
     if (styleAttributes != null)
     {
         style_ = new StyleAttributes();
         styleAttributes.CopyTo(style_);
     }
 }
예제 #4
0
 public bool HasSameStyle(StyleAttributes styleAttributes)
 {
     if (((((styleAttributes.displayStyle == this.displayStyle) &&
            (styleAttributes.scriptLevel == this.scriptLevel)) &&
           ((styleAttributes.color == this.color) && (styleAttributes.background == this.background))) &&
          (((styleAttributes.size == this.size) && (styleAttributes.scale == this.scale)) &&
           ((styleAttributes.isBold == this.isBold) && (styleAttributes.isNormal == this.isNormal)))) &&
         ((((styleAttributes.isItalic == this.isItalic) &&
            (styleAttributes.isDoubleStruck == this.isDoubleStruck)) &&
           ((styleAttributes.isFractur == this.isFractur) && (styleAttributes.isScript == this.isScript))) &&
          ((styleAttributes.isSans == this.isSans) && (styleAttributes.isMonospace == this.isMonospace))))
     {
         return true;
     }
     return false;
 }
예제 #5
0
 public bool HasSameStyle(StyleAttributes styleAttributes)
 {
     if (((((styleAttributes.displayStyle == this.displayStyle) &&
            (styleAttributes.scriptLevel == this.scriptLevel)) &&
           ((styleAttributes.color == this.color) && (styleAttributes.background == this.background))) &&
          (((styleAttributes.size == this.size) && (styleAttributes.scale == this.scale)) &&
           ((styleAttributes.isBold == this.isBold) && (styleAttributes.isNormal == this.isNormal)))) &&
         ((((styleAttributes.isItalic == this.isItalic) &&
            (styleAttributes.isDoubleStruck == this.isDoubleStruck)) &&
           ((styleAttributes.isFractur == this.isFractur) && (styleAttributes.isScript == this.isScript))) &&
          ((styleAttributes.isSans == this.isSans) && (styleAttributes.isMonospace == this.isMonospace))))
     {
         return(true);
     }
     return(false);
 }
예제 #6
0
 public void SetColor(Color _color)
 {
     if (style_ == null)
     {
         style_ = new StyleAttributes();
     }
     style_.canOverride = true;
     style_.color = _color;
     style_.hasColor = true;
     if (HasChildren())
     {
         NodesList list = GetChildrenNodes();
         for (Node node = list.Next(); node != null; node = list.Next())
         {
             node.SetColor(_color);
         }
     }
 }
예제 #7
0
         public void SetStyle(StyleAttributes styleAttributes)
 {
     if (style_ == null)
     {
         style_ = new StyleAttributes();
     }
     styleAttributes.CopyTo(style_);
     style_.canOverride = true;
     if (HasChildren())
     {
         NodesList list = GetChildrenNodes();
         for (Node child = list.Next(); child != null; child = list.Next())
         {
             if (child.type_.type != ElementType.Entity)
             {
                 child.SetStyle(styleAttributes);
             }
         }
     }
 }
예제 #8
0
 public void SetBackground(Color _color)
 {
     if (style_ == null)
     {
         style_ = new StyleAttributes();
     }
     style_.canOverride = true;
     style_.background = _color;
     style_.hasBackground = true;
     if (HasChildren())
     {
         NodesList list = GetChildrenNodes();
         for (Node node = list.Next(); node != null; node = list.Next())
         {
             if (node.type_.type != ElementType.Entity)
             {
                 node.SetBackground(_color);
             }
         }
     }
 }
예제 #9
0
 public void DrawQuote(Node node, int x, int y, string text, int scriptLevel, StyleAttributes styleAttributes, Color color)
 {
     try
     {
         Brush brush;
         int width = 0;
         text = text.Replace("&", "&");
         text = text.Replace(""", "\"");
         text = text.Replace("'", "'");
         text = text.Replace(">", ">");
         text = text.Replace("&lt;", "<");
         if (styleAttributes != null)
         {
             if (node.NotBlack() || (((node.type_.type == ElementType.Entity) && (node.parent_ != null)) && node.parent_.NotBlack()))
             {
                 brush = new SolidBrush(styleAttributes.color);
             }
             else
             {
                 brush = new SolidBrush(color);
             }
         }
         else if (color != Color.Black)
         {
             brush = new SolidBrush(color);
         }
         else
         {
             brush = this.blackBrush;
         }
         if (text == null)
         {
             return;
         }
         int len = text.Length;
         for (int i = 0; i < len; i++)
         {
             
             if (char.IsLetterOrDigit(text[i]) || char.IsPunctuation(text[i]))
             {
                 string s = "" + text[i];
                 PointF point = new PointF((float) ((this.oX + x) + width), (float) (this.oY + y));
                 this.graphics_.DrawString(s, this.GetSuitableFont(node, styleAttributes), brush, point, this.typographicsFormat);
                 width += this.MeasureWidth(node, styleAttributes, s);
             }
             else
             {
                 string s = Convert.ToString(Convert.ToInt32(text[i]), 0x10).ToUpper();
                 s = s.PadLeft(5, '0');
                 Glyph glyph = this.entityManager.ByUnicode(s);
                 if (glyph != null)
                 {
                     node.glyph = glyph;
                     System.Drawing.Font f = this.MakeGlyphFont(node, scriptLevel, styleAttributes);
                     if (f != null)
                     {
                         PointF point = new PointF((float) ((this.oX + x) + width), (float) (this.oY + y));
                         string gs = "" + glyph.CharValue;
                         if (color == Color.Black)
                         {
                             this.graphics_.DrawString(gs, f, brush, point, this.typographicsFormat);
                         }
                         else
                         {
                             this.graphics_.DrawString(gs, f, new SolidBrush(color), point, this.typographicsFormat);
                         }
                         width += this.MeasureWidth(node, styleAttributes, gs);
                     }
                     node.glyph = null;
                 }
             }
         }
     }
     catch
     {
     }
 }
예제 #10
0
 public Rectangle CalcRect(Node node, StyleAttributes styleAttributes)
 {
     Rectangle r = new Rectangle(0, 0, 0, 0);
     try
     {
         Size size = this.graphics_.MeasureString("X", this.GetSuitableFont(node, styleAttributes), new PointF(0f, 0f), this.typographicsFormat).ToSize();
         r.Width = size.Width;
         r.Height = size.Height;
     }
     catch
     {
     }
     return r;
 }
예제 #11
0
 public BoxRect MeasureTextRect(Node node, string text, int scriptLevel, StyleAttributes styleAttributes)
 {
     BoxRect rect = new BoxRect();
     int maxb = 0;
     int maxd = 0;
     try
     {
         text = text.Replace("&amp;", "&");
         text = text.Replace("&quot;", "\"");
         text = text.Replace("&apos;", "'");
         text = text.Replace("&gt;", ">");
         text = text.Replace("&lt;", "<");
         if (text != null)
         {
             int len = text.Length;
             for (int i = 0; i < len; i++)
             {
                 if (char.IsLetterOrDigit(text[i]) || char.IsPunctuation(text[i]))
                 {
                     rect.width += this.MeasureWidth(node, styleAttributes, "" + text[i]);
                     int h = this.MeasureHeight(node, styleAttributes, "" + text[i]);
                     int b = this.MeasureBaseline(node, styleAttributes, "" + text[i]);
                     if (b > maxb)
                     {
                         maxb = b;
                     }
                     if ((h - b) > maxd)
                     {
                         maxd = h - b;
                     }
                 }
                 else
                 {
                     string hex = "";
                     hex = Convert.ToString(text[i], 0x10).ToUpper();
                     hex = hex.PadLeft(5, '0');
                     Glyph glyph = this.entityManager.ByUnicode(hex);
                     if (glyph != null)
                     {
                         node.glyph = glyph;
                         if (this.MakeGlyphFont(node, scriptLevel, styleAttributes) != null)
                         {
                             rect.width += this.MeasureWidth(node, styleAttributes, "" + glyph.CharValue);
                             int h = this.MeasureHeight(node, styleAttributes, "" + glyph.CharValue);
                             int b = this.MeasureBaseline(node, styleAttributes, "" + glyph.CharValue);
                             if (b > maxb)
                             {
                                 maxb = b;
                             }
                             if ((h - b) > maxd)
                             {
                                 maxd = h - b;
                             }
                         }
                         node.glyph = null;
                     }
                 }
             }
         }
     }
     catch
     {
         rect = new BoxRect(10, 10, 5);
     }
     rect.height = Math.Max(maxb + maxd, 10);
     rect.baseline = Math.Max(maxb, 8);
     return rect;
 }
예제 #12
0
 public int MeasureHeight(Node node, StyleAttributes styleAttributes, string text)
 {
     int r = 0;
     if ((node != null) && (node.box != null))
     {
         int w = node.box.Width;
         int h = node.box.Height;
         int baseline = node.box.Baseline;
         int dy = node.box.Dy;
         int dx = node.box.Dx;
         try
         {
             this.MeasureBox(node, styleAttributes, text);
             r = node.box.Height;
         }
         catch
         {
         }
         node.box.Width = w;
         node.box.Height = h;
         node.box.Baseline = baseline;
         node.box.Dx = dx;
         node.box.Dy = dy;
     }
     return r;
 }
예제 #13
0
 public int MeasureWidth(Node node, StyleAttributes styleAttributes, string text)
 {
     int w = 0;
     bool startSpace = false;
     bool endSpace = false;
     if ((text.Length > 0) && char.IsWhiteSpace(text[0]))
     {
         startSpace = true;
     }
     if ((text.Length > 0) && char.IsWhiteSpace(text[text.Length - 1]))
     {
         endSpace = true;
     }
     if (startSpace || endSpace)
     {
         w = this.MeasureWidth(node, styleAttributes, "I");
         if (startSpace && endSpace)
         {
             text = "I" + text + "I";
         }
         else if (startSpace)
         {
             text = "I" + text;
         }
         else if (endSpace)
         {
             text = text + "I";
         }
     }
     int r = 0;
     if ((node != null) && (node.box != null))
     {
         int ww = node.box.Width;
         int h = node.box.Height;
         int b = node.box.Baseline;
         int dy = node.box.Dy;
         int dx = node.box.Dx;
         try
         {
             this.MeasureBox(node, styleAttributes, text);
             r = node.box.Width;
         }
         catch
         {
         }
         if (startSpace || endSpace)
         {
             if (startSpace && endSpace)
             {
                 r -= 2 * w;
             }
             else if (startSpace)
             {
                 r -= w;
             }
             else if (endSpace)
             {
                 r -= w;
             }
         }
         node.box.Width = ww;
         node.box.Height = h;
         node.box.Baseline = b;
         node.box.Dx = dx;
         node.box.Dy = dy;
     }
     return r;
 }
예제 #14
0
 public float FontSize(Node node, StyleAttributes styleAttributes)
 {
     float r = 1f;
     try
     {
         System.Drawing.Font f = this.GetSuitableFont(node, node.style_);
         if (f != null)
         {
             r = this.FontSize(f);
         }
     }
     catch
     {
     }
     return r;
 }
예제 #15
0
        public static void CascadeStyles(Node parentNode, Node node, StyleAttributes styleAttributes)
        {
            string fontSize;
            string mathSize;
            if ((node == null) || (styleAttributes == null))
            {
                return;
            }
            
            if (node.style_ == null)
            {
                string font = styleAttributes.FontToString();
                if (font == "")
                {
                    if (node.attrs != null)
                    {
                        Nodes.Attribute attribute = node.attrs.Get("mathvariant");
                        if (attribute != null)
                        {
                            node.attrs.Remove(attribute);
                        }
                    }
                }
                else
                {
                    if (node.attrs == null)
                    {
                        node.attrs = new AttributeList();
                    }
                    if (font.Length > 0)
                    {
                        node.attrs.Add("mathvariant", font);
                    }
                }
                
                if (styleAttributes.displayStyle == DisplayStyle.AUTOMATIC)
                {
                    if (node.attrs != null)
                    {
                        Nodes.Attribute attribute = node.attrs.Get("displaystyle");
                        if (attribute != null)
                        {
                            node.attrs.Remove(attribute);
                        }
                    }
                }
                else
                {
                    if (node.attrs == null)
                    {
                        node.attrs = new AttributeList();
                    }

                    switch (styleAttributes.displayStyle)
                    {
                        case DisplayStyle.TRUE:
                        {
                            node.attrs.Add("displaystyle", "true");
                            break;
                        }
                        case DisplayStyle.FALSE:
                        {
                            node.attrs.Add("displaystyle", "false");
                            break;
                        }
                    }
                }
            }
            else
            {
                string fontToString = "";
                string styleFont = "";
                fontToString = styleAttributes.FontToString();
                styleFont = node.style_.FontToString();
                if ((fontToString.Length > 0) && (fontToString != styleFont))
                {
                    if (node.attrs == null)
                    {
                        node.attrs = new AttributeList();
                    }
                    node.attrs.Add("mathvariant", fontToString);
                }
                else if (node.attrs != null)
                {
                    Nodes.Attribute attribute = node.attrs.Get("mathvariant");
                    if (attribute != null)
                    {
                        node.attrs.Remove(attribute);
                    }
                }
                
                bool topLevel = false;
                bool hasDisplayStyle = false;
                if (((parentNode != null) && (parentNode.type_ != null)) && (parentNode.type_.type == ElementType.Math))
                {
                    topLevel = true;
                }
                DisplayStyle displayStyle = styleAttributes.displayStyle;
                DisplayStyle styleDisplayStyle = node.style_.displayStyle;
                if ((topLevel && (parentNode != null)) &&
                    (((displayStyle == DisplayStyle.TRUE) && parentNode.displayStyle) ||
                     ((displayStyle == DisplayStyle.FALSE) && !parentNode.displayStyle)))
                {
                    hasDisplayStyle = true;
                }
                if (((displayStyle != styleDisplayStyle) && (displayStyle != DisplayStyle.AUTOMATIC)) && !hasDisplayStyle)
                {
                    if (node.attrs == null)
                    {
                        node.attrs = new AttributeList();
                    }
                    switch (displayStyle)
                    {
                        case DisplayStyle.TRUE:
                        {
                            node.attrs.Add("displaystyle", "true");
                            break;
                        }
                        case DisplayStyle.FALSE:
                        {
                            node.attrs.Add("displaystyle", "false");
                            break;
                        }
                    }
                }
                else if (node.attrs != null)
                {
                    Nodes.Attribute attribute = node.attrs.Get("displaystyle");
                    if (attribute != null)
                    {
                        node.attrs.Remove(attribute);
                    }
                }
                
                hasDisplayStyle = false;
                ScriptLevel scriptLevel = styleAttributes.scriptLevel;
                ScriptLevel styleScriptLevel = node.style_.scriptLevel;
                if ((topLevel && (parentNode != null)) &&
                    ((((scriptLevel == ScriptLevel.ZERO) && (parentNode.scriptLevel_ == 0)) ||
                      ((scriptLevel == ScriptLevel.ONE) && (parentNode.scriptLevel_ == 1))) ||
                     ((scriptLevel == ScriptLevel.TWO) && (parentNode.scriptLevel_ == 2))))
                {
                    hasDisplayStyle = true;
                }
                if (((scriptLevel != styleScriptLevel) && (scriptLevel != ScriptLevel.NONE)) && !hasDisplayStyle)
                {
                    if (node.attrs == null)
                    {
                        node.attrs = new AttributeList();
                    }
                    switch (scriptLevel)
                    {
                        case ScriptLevel.ZERO:
                        {
                            node.attrs.Add("scriptlevel", "0");
                            break;
                        }
                        case ScriptLevel.ONE:
                        {
                            node.attrs.Add("scriptlevel", "1");
                            break;
                        }
                        case ScriptLevel.TWO:
                        {
                            node.attrs.Add("scriptlevel", "2");
                            break;
                        }
                        case ScriptLevel.PLUS_ONE:
                        {
                            node.attrs.Add("scriptlevel", "+1");
                            break;
                        }
                        case ScriptLevel.PLUS_TWO:
                        {
                            node.attrs.Add("scriptlevel", "+2");
                            break;
                        }
                        case ScriptLevel.MINUS_ONE:
                        {
                            node.attrs.Add("scriptlevel", "-1");
                            break;
                        }
                        case ScriptLevel.MINUS_TWO:
                        {
                            node.attrs.Add("scriptlevel", "-2");
                            break;
                        }
                    }
                }
                else if (node.attrs != null)
                {
                    Nodes.Attribute attribute = node.attrs.Get("scriptlevel");
                    if (attribute != null)
                    {
                        node.attrs.Remove(attribute);
                    }
                }
                
                fontSize = "";
                string ownFontSize = "";
                fontSize = styleAttributes.FontSize();
                ownFontSize = node.style_.FontSize();
                if (fontSize != ownFontSize)
                {
                    if (node.attrs == null)
                    {
                        node.attrs = new AttributeList();
                    }
                    if (fontSize.Length > 0)
                    {
                        node.attrs.Add("mathsize", fontSize);
                    }
                }
                else if (node.attrs != null)
                {
                    Nodes.Attribute attribute = node.attrs.Get("mathsize");
                    if (attribute != null)
                    {
                        node.attrs.Remove(attribute);
                    }
                }
                if (styleAttributes.color != node.style_.color)
                {
                    if (node.attrs == null)
                    {
                        node.attrs = new AttributeList();
                    }
                    node.attrs.Add("mathcolor", ColorTranslator.ToHtml(styleAttributes.color));
                }
                else if (node.attrs != null)
                {
                    Nodes.Attribute attribute = node.attrs.Get("mathcolor");
                    if (attribute != null)
                    {
                        node.attrs.Remove(attribute);
                    }
                }
                if (styleAttributes.background != node.style_.background)
                {
                    if (node.attrs == null)
                    {
                        node.attrs = new AttributeList();
                    }
                    node.attrs.Add("mathbackground", ColorTranslator.ToHtml(styleAttributes.background));
                    return;
                }
                if (node.attrs != null)
                {
                    Nodes.Attribute attribute = node.attrs.Get("mathbackground");
                    if (attribute == null)
                    {
                        return;
                    }
                    node.attrs.Remove(attribute);
                }
                return;
            }
        
            if (styleAttributes.scriptLevel == ScriptLevel.NONE)
            {
                if (node.attrs != null)
                {
                    Nodes.Attribute attribute = node.attrs.Get("scriptlevel");
                    if (attribute != null)
                    {
                        node.attrs.Remove(attribute);
                    }
                }
            }
            else
            {
                if (node.attrs == null)
                {
                    node.attrs = new AttributeList();
                }
                switch (styleAttributes.scriptLevel)
                {
                    case ScriptLevel.ZERO:
                    {
                        node.attrs.Add("scriptlevel", "0");
                        break;
                    }
                    case ScriptLevel.ONE:
                    {
                        node.attrs.Add("scriptlevel", "1");
                        break;
                    }
                    case ScriptLevel.TWO:
                    {
                        node.attrs.Add("scriptlevel", "2");
                        break;
                    }
                    case ScriptLevel.PLUS_ONE:
                    {
                        node.attrs.Add("scriptlevel", "+1");
                        break;
                    }
                    case ScriptLevel.PLUS_TWO:
                    {
                        node.attrs.Add("scriptlevel", "+2");
                        break;
                    }
                    case ScriptLevel.MINUS_ONE:
                    {
                        node.attrs.Add("scriptlevel", "-1");
                        break;
                    }
                    case ScriptLevel.MINUS_TWO:
                    {
                        node.attrs.Add("scriptlevel", "-2");
                        break;
                    }
                }
            }
        
            mathSize = "";
            mathSize = styleAttributes.FontSize();
            if (mathSize == "normal")
            {
                if (node.attrs != null)
                {
                    Nodes.Attribute attribute = node.attrs.Get("mathsize");
                    if (attribute != null)
                    {
                        node.attrs.Remove(attribute);
                    }
                }
            }
            else
            {
                if (node.attrs == null)
                {
                    node.attrs = new AttributeList();
                }
                if (mathSize.Length > 0)
                {
                    node.attrs.Add("mathsize", mathSize);
                }
            }
            if (styleAttributes.color == Color.Black)
            {
                if (node.attrs != null)
                {
                    Nodes.Attribute attribute = node.attrs.Get("mathcolor");
                    if (attribute != null)
                    {
                        node.attrs.Remove(attribute);
                    }
                }
            }
            else
            {
                if (node.attrs == null)
                {
                    node.attrs = new AttributeList();
                }
                node.attrs.Add("mathcolor", ColorTranslator.ToHtml(styleAttributes.color));
            }
            if (styleAttributes.background == Color.White)
            {
                if (node.attrs == null)
                {
                    return;
                }
                Nodes.Attribute attribute = node.attrs.Get("mathbackground");
                if (attribute == null)
                {
                    return;
                }
                node.attrs.Remove(attribute);
            }
            else
            {
                if (node.attrs == null)
                {
                    node.attrs = new AttributeList();
                }
                node.attrs.Add("mathbackground", ColorTranslator.ToHtml(styleAttributes.background));
            }
        }
예제 #16
0
 public void MeasureBox(Node node, StyleAttributes styleAttributes)
 {
     this.MeasureBox(node, styleAttributes, node.literalText);
 }
예제 #17
0
 //
 public void ApplyStyleToSelection (StyleAttributes styleAttributes)
 {
     try
     {
         this.OnInsert (false);
         if (this.hasSelection)
         {
             {
                 Selection sel = this.CaptureSelection();
                 if (sel != null)
                 {
                     this.ApplyStyleToSelection(styleAttributes, sel);
                 }
             }
         }
         else
         {
             Node cur = this.GetCurrentlySelectedNode ();
             if ((((cur != null) && (cur.InternalMark == 0)) &&
                  ((cur.type_ != null))) &&
                 (cur.type_.type != ElementType.Math))
             {
                 styleAttributes.hasBackground = true;
                 styleAttributes.hasColor = true;
                 cur.SetStyle (styleAttributes);
             }
         }
     }
     catch
     {
     }
 }
예제 #18
0
 //
 private void ApplyStyleToSelection (StyleAttributes styleAttributes, Selection selectionCollection)
 {
     try
     {
         if (((selectionCollection == null) || (selectionCollection.nodesList.Count <= 0)))
         {
             return;
         }
         int count = selectionCollection.nodesList.Count;
         selectionCollection.nodesList.Reset ();
         for (int i = 0; i < count; i++)
         {
             Node n = selectionCollection.nodesList.Next ();
             if (((i <= 0) || (n != selectionCollection.Last)) || (selectionCollection.literalLength != 0))
             {
                 styleAttributes.hasBackground = true;
                 styleAttributes.hasColor = true;
                 n.SetStyle (styleAttributes);
             }
         }
         selectionCollection.nodesList.Reset ();
     }
     catch
     {
     }
 }
예제 #19
0
 public int roundOpFontSize(Node node, StyleAttributes styleAttributes)
 {
     int roundFontSize = 0;
     try
     {
         roundFontSize = this.RoundFontSize(this.operatorFontSize(node, styleAttributes));
     }
     catch
     {
     }
     return Math.Max(roundFontSize, 1);
 }
예제 #20
0
 //
 public StyleAttributes GetSelectionStyle ()
 {
     StyleAttributes style = new StyleAttributes ();
     try
     {
         if (!this.hasSelection)
         {
             return style;
         }
         
         Selection sel = this.CaptureSelection ();
         if (sel != null)
         {
             style = this.GetSelectionStyle (style, sel);
         }
     }
     catch
     {
     }
     return style;
 }
예제 #21
0
 public void SetScale(double scaling)
 {
     if (style_ == null)
     {
         style_ = new StyleAttributes();
     }
     if (scaling == 1)
     {
         style_.hasSize = false;
         style_.size = "";
         style_.scale = 1;
         style_.canOverride = true;
     }
     else
     {
         style_.hasSize = true;
         style_.scale = scaling;
         string size = (scaling*100).ToString();
         size = size.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, ".");
         size = size + "%";
         style_.size = size;
         style_.canOverride = true;
     }
     if (HasChildren())
     {
         NodesList list = GetChildrenNodes();
         for (Node node = list.Next(); node != null; node = list.Next())
         {
             if (node.type_.type != ElementType.Entity)
             {
                 node.SetScale(scaling);
             }
         }
     }
 }
예제 #22
0
 public static StyleAttributes StyleAttrsFromNode(Node node, bool bMStyle)
 {
     Nodes.Attribute attribute = null;
     StyleAttributes attributes = null;
     try
     {
         if (node.attrs == null)
         {
             return attributes;
         }
         node.attrs.Reset();
         for (attribute = node.attrs.Next(); attribute != null; attribute = node.attrs.Next())
         {
             string s = attribute.val.Trim();
             if (bMStyle && (attribute.name == "displaystyle"))
             {
                 if (s.ToUpper() == "TRUE")
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.displayStyle = DisplayStyle.TRUE;
                 }
                 else if (s.ToUpper() == "FALSE")
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.displayStyle = DisplayStyle.FALSE;
                 }
             }
             else if (bMStyle && (attribute.name == "scriptlevel"))
             {
                 s = s.Trim();
                 string levelStr = "";
                 int level = 0;
                 bool plus = false;
                 bool minus = false;
                 if ((s.Length > 0) && (s[0] == '+'))
                 {
                     plus = true;
                     levelStr = s.Substring(1, s.Length - 1);
                 }
                 else if ((s.Length > 0) && (s[0] == '-'))
                 {
                     minus = true;
                     levelStr = s.Substring(1, s.Length - 1);
                 }
                 else
                 {
                     levelStr = s;
                 }
                 try
                 {
                     level = Convert.ToInt32(levelStr);
                     if (level > 2)
                     {
                         level = 2;
                     }
                     if (level < 0)
                     {
                         level = 0;
                     }
                 }
                 catch
                 {
                     level = 0;
                 }
                 if (plus && (level == 1))
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.scriptLevel = ScriptLevel.PLUS_ONE;
                 }
                 else if (plus && (level == 2))
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.scriptLevel = ScriptLevel.PLUS_TWO;
                 }
                 else if (minus && (level == 1))
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.scriptLevel = ScriptLevel.MINUS_TWO;
                 }
                 else if (minus && (level == 2))
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.scriptLevel = ScriptLevel.MINUS_TWO;
                 }
                 else if ((!plus && !minus) && (level == 0))
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.scriptLevel = ScriptLevel.ZERO;
                 }
                 else if ((!plus && !minus) && (level == 1))
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.scriptLevel = ScriptLevel.ONE;
                 }
                 else if ((!plus && !minus) && (level == 2))
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.scriptLevel = ScriptLevel.TWO;
                 }
             }
             else if (attribute.name == "mathvariant")
             {
                 if (s.Length > 0)
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     if (s == "fraktur")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = false;
                         attributes.isItalic = false;
                         attributes.isFractur = true;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else if (s == "bold")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = true;
                         attributes.isItalic = false;
                         attributes.isFractur = false;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else if (s == "bold-italic")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = true;
                         attributes.isItalic = true;
                         attributes.isFractur = false;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else if (s == "bold-fraktur")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = true;
                         attributes.isItalic = false;
                         attributes.isFractur = true;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else if (s == "bold-script")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = true;
                         attributes.isItalic = false;
                         attributes.isFractur = false;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = true;
                         attributes.isMonospace = false;
                     }
                     else if (s == "bold-sans-serif")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = true;
                         attributes.isItalic = false;
                         attributes.isFractur = false;
                         attributes.isSans = true;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else if (s == "italic")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = false;
                         attributes.isItalic = true;
                         attributes.isFractur = false;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else if (s == "sans-serif-italic")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = false;
                         attributes.isItalic = true;
                         attributes.isFractur = false;
                         attributes.isSans = true;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else if (s == "sans-serif-bold-italic")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = true;
                         attributes.isItalic = true;
                         attributes.isFractur = false;
                         attributes.isSans = true;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else if (s == "double-struck")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = false;
                         attributes.isItalic = false;
                         attributes.isFractur = false;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = true;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else if (s == "monospace")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = false;
                         attributes.isItalic = false;
                         attributes.isFractur = false;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = true;
                     }
                     else if (s == "script")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = false;
                         attributes.isItalic = false;
                         attributes.isFractur = false;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = true;
                         attributes.isMonospace = false;
                     }
                     else if (s == "sans-serif")
                     {
                         attributes.isNormal = false;
                         attributes.isBold = false;
                         attributes.isItalic = false;
                         attributes.isFractur = false;
                         attributes.isSans = true;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else if (s == "normal")
                     {
                         attributes.isNormal = true;
                         attributes.isBold = false;
                         attributes.isItalic = false;
                         attributes.isFractur = false;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                     else
                     {
                         attributes.isNormal = false;
                         attributes.isBold = false;
                         attributes.isItalic = false;
                         attributes.isFractur = false;
                         attributes.isSans = false;
                         attributes.isDoubleStruck = false;
                         attributes.isScript = false;
                         attributes.isMonospace = false;
                     }
                 }
             }
             else if (attribute.name == "mathcolor")
             {
                 if (s.Length > 0)
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.color = ColorTranslator.FromHtml(s);
                 }
                 attributes.hasColor = true;
             }
             else if (attribute.name == "mathbackground")
             {
                 if (s.Length > 0)
                 {
                     if (attributes == null)
                     {
                         attributes = new StyleAttributes();
                     }
                     attributes.background = ColorTranslator.FromHtml(s);
                 }
                 attributes.hasBackground = true;
             }
             if ((attribute.name == "mathsize") && (s.Length > 0))
             {
                 if (attributes == null)
                 {
                     attributes = new StyleAttributes();
                 }
                 attributes.size = s;
                 attributes.hasSize = true;
             }
         }
         node.attrs.Reset();
     }
     catch
     {
     }
     return attributes;
 }
예제 #23
0
 public System.Drawing.Font GetSuitableFont(Node node, StyleAttributes styleAttributes)
 {
     if (node.glyph != null)
     {
         return this.MakeGlyphFont(node, node.scriptLevel_, styleAttributes);
     }
     if (node.type_.type == ElementType.Mn)
     {
         return this.MakeFont(node, 0, Category.NUMBER, node.scriptLevel_, styleAttributes);
     }
     if (((node.tokenType == Tokens.TEXT) || (node.type_.type == ElementType.Entity)) || (node.type_.type == ElementType.Mo))
     {
         return this.MakeFont(node, 0, Category.OPERATOR, node.scriptLevel_, styleAttributes);
     }
     if (node.type_.type == ElementType.Mglyph)
     {
         return this.MakeFont(node, 0, Category.GLYPH, node.scriptLevel_, styleAttributes);
     }
     return this.MakeFont(node, 0, Category.UNKNOWN, node.scriptLevel_, styleAttributes);
 }
예제 #24
0
 public bool IsSameStyleParent()
 {
     if (parent_ != null)
     {
         if ((style_ != null) && (parent_.style_ == null))
         {
             StyleAttributes styleAttributes = new StyleAttributes();
             if (!styleAttributes.HasSameStyle(style_))
             {
                 return true;
             }
         }
         else if ((style_ == null) && (parent_.style_ != null))
         {
             StyleAttributes styleAttributes = new StyleAttributes();
             if (!styleAttributes.HasSameStyle(parent_.style_))
             {
                 return true;
             }
         }
         else if (((style_ != null) && (parent_.style_ != null)) &&
                  !parent_.style_.HasSameStyle(style_))
         {
             if (parent_.type_.type == ElementType.Math)
             {
                 StyleAttributes styleAttributes = new StyleAttributes();
                 if (styleAttributes.HasSameStyle(style_))
                 {
                     return false;
                 }
             }
             return true;
         }
     }
     return false;
 }
예제 #25
0
 public System.Drawing.Font MakeGlyphFont(Node node, int scriptLevel, StyleAttributes styleAttributes)
 {
     System.Drawing.Font r = null;
     bool hasMax = false;
     bool hasMin = false;
     double scale = 1;
     System.Drawing.FontStyle style = System.Drawing.FontStyle.Regular;
     if (styleAttributes != null)
     {
         scale = styleAttributes.scale;
         if (styleAttributes.isBold)
         {
             style |= System.Drawing.FontStyle.Bold;
         }
         if (styleAttributes.isItalic)
         {
             style |= System.Drawing.FontStyle.Italic;
         }
     }
     if (node.glyph != null)
     {
         if ((node.parent_ != null) && (node.parent_.type_.type == ElementType.Mi))
         {
             if (styleAttributes != null)
             {
                 if (styleAttributes.isTop)
                 {
                     style |= System.Drawing.FontStyle.Italic;
                 }
                 else if (((!styleAttributes.isNormal && !styleAttributes.isBold) && (!styleAttributes.isDoubleStruck && !styleAttributes.isFractur)) && ((!styleAttributes.isMonospace && !styleAttributes.isSans) && !styleAttributes.isScript))
                 {
                     style |= System.Drawing.FontStyle.Italic;
                 }
             }
             else
             {
                 style |= System.Drawing.FontStyle.Italic;
             }
         }
         string fontName = "Symbol";
         if (node.glyph.FontFamily.Length > 0)
         {
             fontName = node.glyph.FontFamily;
             if (node.glyph.FontFamily == "ESSTIXNine")
             {
                 if ((style & System.Drawing.FontStyle.Italic) == System.Drawing.FontStyle.Italic)
                 {
                     style &= ~System.Drawing.FontStyle.Italic;
                 }
                 else
                 {
                     fontName = "ESSTIXTen";
                 }
             }
             else if ((node.glyph.FontFamily == "ESSTIXTen") && ((style & System.Drawing.FontStyle.Italic) == System.Drawing.FontStyle.Italic))
             {
                 fontName = "ESSTIXNine";
                 style &= ~System.Drawing.FontStyle.Italic;
             }
         }
         if ((node.type_.type == ElementType.Entity) && (node.glyph != null))
         {
             bool notAuto = false;
             bool hasDisplayStyle = true;
             bool dispTrue = false;
             if (node.parent_ != null)
             {
                 hasDisplayStyle = node.parent_.displayStyle;
             }
             if (((node.parent_ != null) && (node.parent_.type_.type == ElementType.Mo)) && (node.parent_.attrs != null))
             {
                 string largeop = node.parent_.attrs.GetValue("largeop");
                 if (node.parent_.attrs.Get("maxsize") != null)
                 {
                     hasMax = true;
                 }
                 if (node.parent_.attrs.Get("minsize") != null)
                 {
                     hasMin = true;
                 }
                 switch (largeop.Trim().ToUpper())
                 {
                     case "TRUE":
                     {
                         notAuto = true;
                         dispTrue = true;
                         break;
                     }
                     case "FALSE":
                     {
                         notAuto = false;
                         dispTrue = true;
                         break;
                     }
                 }
             }
             if ((dispTrue && notAuto) && hasDisplayStyle)
             {
                 scale *= 1.5;
             }
             else if ((!dispTrue && hasDisplayStyle) && (((((node.glyph.Code == "0222B") || (node.glyph.Code == "0222C")) || ((node.glyph.Code == "0222D") || (node.glyph.Code == "0222E"))) || (((node.glyph.Code == "02232") || (node.glyph.Code == "02233")) || ((node.glyph.Code == "0222F") || (node.glyph.Code == "02230")))) || ((((node.glyph.Code == "02211") || (node.glyph.Code == "0220F")) || ((node.glyph.Code == "02210") || (node.glyph.Code == "022C2"))) || (((node.glyph.Code == "022C3") || (node.glyph.Code == "022C0")) || (((node.glyph.Code == "022C1") || (node.glyph.Code == "02294")) || (node.glyph.Code == "0228E"))))))
             {
                 scale *= 1.5;
             }
         }
         FontFamily fam = null;
         if (this.fonts_ != null)
         {
             fam = this.fonts_.Get(fontName);
         }
         if (fam != null)
         {
             switch (node.scriptLevel_)
             {
                 case 0:
                 {
                     r = new System.Drawing.Font(fam, (float) (this.textSize * scale), style);
                     if (hasMin || hasMax)
                     {
                         r = new System.Drawing.Font(fam, (float) ((this.textSize * this.FontScale(r, node.parent_)) * scale), style);
                     }
                     break;
                 }
                 case 1:
                 {
                     r = new System.Drawing.Font(fam, (float) ((this.textSize * 0.71) * scale), style);
                     if (hasMin || hasMax)
                     {
                         r = new System.Drawing.Font(fam, (float) (((this.textSize * this.FontScale(r, node.parent_)) * 0.71) * scale), style);
                     }
                     break;
                 }
                 case 2:
                 {
                     r = new System.Drawing.Font(fam, (float) ((this.textSize * 0.5) * scale), style);
                     if (hasMin || hasMax)
                     {
                         r = new System.Drawing.Font(fam, (float) (((this.textSize * this.FontScale(r, node.parent_)) * 0.5) * scale), style);
                     }
                     break;
                 }
             }
         }
         else
         {
             switch (node.scriptLevel_)
             {
                 case 0:
                 {
                     r = new System.Drawing.Font(fontName, (float) (this.textSize * scale), style);
                     if (hasMin || hasMax)
                     {
                         r = new System.Drawing.Font(fontName, (float) ((this.textSize * this.FontScale(r, node.parent_)) * scale), style);
                     }
                     break;
                 }
                 case 1:
                 {
                     r = new System.Drawing.Font(fontName, (float) ((this.textSize * 0.71) * scale), style);
                     if (hasMin || hasMax)
                     {
                         r = new System.Drawing.Font(fontName, (float) (((this.textSize * this.FontScale(r, node.parent_)) * 0.71) * scale), style);
                     }
                     break;
                 }
                 case 2:
                 {
                     r = new System.Drawing.Font(fontName, (float) ((this.textSize * 0.5) * scale), style);
                     if (hasMin || hasMax)
                     {
                         r = new System.Drawing.Font(fontName, (float) (((this.textSize * this.FontScale(r, node.parent_)) * 0.5) * scale), style);
                     }
                     break;
                 }
             }
         }
     }
 
     if (r == null)
     {
         r = new System.Drawing.Font("Symbol", this.textSize);
     }
     return r;
 }
예제 #26
0
 public bool IsSameStyle(Node node)
 {
     if ((style_ == null) && (node.style_ == null))
     {
         return true;
     }
     if ((style_ != null) && (node.style_ == null))
     {
         StyleAttributes styleAttributes = new StyleAttributes();
         if (styleAttributes.HasSameStyle(style_))
         {
             return true;
         }
     }
     else if ((style_ == null) && (node.style_ != null))
     {
         StyleAttributes styleAttributes = new StyleAttributes();
         if (styleAttributes.HasSameStyle(node.style_))
         {
             return true;
         }
     }
     else if (((style_ != null) && (node.style_ != null)) &&
              style_.HasSameStyle(node.style_))
     {
         return true;
     }
     return false;
 }
예제 #27
0
        public float CalcSpaceHeight(Space Space, Node node, StyleAttributes styleAttributes)
        {
            
            try
            {
                return this.CalcSpaceHeight(Space, this.FontSize(node, styleAttributes));
            }
            catch
            {
				return 0f;
            }
        }
예제 #28
0
 //
 private StyleAttributes GetSelectionStyle (StyleAttributes styleAttributes, Selection selectionCollection)
 {
     try
     {
         if (((selectionCollection == null) || (selectionCollection.nodesList.Count <= 0)))
         {
             return styleAttributes;
         }
         int count = selectionCollection.nodesList.Count;
         Node n = selectionCollection.nodesList.Next ();
         if (n.style_ != null)
         {
             n.style_.CopyTo (styleAttributes);
             return styleAttributes;
         }
         styleAttributes = new StyleAttributes ();
     }
     catch
     {
     }
     return styleAttributes;
 }
예제 #29
0
        public double operatorFontSize(Node node, StyleAttributes styleAttributes)
        {
            try
            {
                return (this.FontSize(this.GetSuitableFont(node, node.style_)) * 0.07741);
            }
            catch
            {
				return 0;
            }
        }
예제 #30
0
 public void CombineStyles(StyleAttributes first, StyleAttributes second)
 {
     try
     {
         if (style_ == null)
         {
             return;
         }
         if (first.hasColor)
         {
             style_.color = first.color;
             style_.hasColor = true;
         }
         else
         {
             style_.color = second.color;
             style_.hasColor = false;
         }
         if (first.hasBackground)
         {
             style_.background = first.background;
             style_.hasBackground = true;
         }
         else
         {
             style_.background = second.background;
             style_.hasBackground = false;
         }
         if (first.hasSize)
         {
             style_.scale = first.scale;
             style_.size = first.size;
             style_.hasSize = true;
         }
         else
         {
             style_.scale = second.scale;
             style_.size = second.size;
             style_.hasSize = false;
         }
         if (first.IsStyled)
         {
             style_.isBold = first.isBold;
             style_.isItalic = first.isItalic;
             style_.isUnderline = first.isUnderline;
             style_.isNormal = first.isNormal;
             style_.isMonospace = first.isMonospace;
             style_.isScript = first.isScript;
             style_.isSans = first.isSans;
             style_.isFractur = first.isFractur;
             style_.isDoubleStruck = first.isDoubleStruck;
         }
         else
         {
             style_.isBold = second.isBold;
             style_.isItalic = second.isItalic;
             style_.isUnderline = second.isUnderline;
             style_.isNormal = second.isNormal;
             style_.isMonospace = second.isMonospace;
             style_.isScript = second.isScript;
             style_.isSans = second.isSans;
             style_.isFractur = second.isFractur;
             style_.isDoubleStruck = second.isDoubleStruck;
         }
         if (type_.type == ElementType.Math)
         {
             style_.fontFamily = "";
             style_.isUnderline = false;
         }
     }
     catch
     {
     }
 }
예제 #31
0
 public void MeasureBox(Node node, StyleAttributes styleAttributes, string text)
 {
     SizeF sizeF;
     float height = 0f;
     float width = 0f;
     float baseline = 0f;
     float dy = 0f;
     int dY = 0;
     int xCorr = 0;
     if ((node.type_.type == ElementType.Entity) && (node.glyph != null))
     {
         if (node.glyph.Code == "0F578")
         {
             text = "$" + text;
         }
         else if (node.glyph.Code == "0F576")
         {
             text = text + "$";
         }
         else if (node.glyph.Code == "0F577")
         {
             text = "$" + text;
         }
         else if (node.glyph.Code == "021C4")
         {
             text = "$" + text;
         }
         else if (node.glyph.Code == "021C6")
         {
             text = "$" + text;
         }
         else if (node.glyph.Code == "021CC")
         {
             text = "$" + text;
         }
         else if (node.glyph.Code == "021CB")
         {
             text = "$" + text;
         }
         else if (node.glyph.Code == "0FE37")
         {
             text = "D" + text + "F";
         }
         else if (node.glyph.Code == "0FE38")
         {
             text = "?" + text + "A";
         }
         else if (node.glyph.Code == "000A8")
         {
             text = text + text;
         }
     }
     PointF origin = new PointF(0f, 0f);
     System.Drawing.Font f = this.GetSuitableFont(node, styleAttributes);
     if (((node.glyph != null) && node.glyph.IsVisible) && ((node.glyph.Category.Name != "Spaces") && (node.glyph.FontFamily.Length == 0)))
     {
         sizeF = this.graphics_.MeasureString("?", f, origin, this.typographicsFormat);
     }
     else
     {
         bool isX = false;
         bool isF = false;
         if ((((node.type_ != null)) && ((f != null) && f.Italic)) && (text.Length > 0))
         {
             char ch = text[text.Length - 1];
             if (char.IsLetter(ch))
             {
                 if (char.IsUpper(ch))
                 {
                     if ((((ch == 'X') || (ch == 'Y')) || ((ch == 'H') || (ch == 'I'))) || ((((ch == 'J') || (ch == 'M')) || ((ch == 'N') || (ch == 'T'))) || (((ch == 'U') || (ch == 'V')) || (ch == 'W'))))
                     {
                         isX = true;
                     }
                 }
                 else if (ch == 'f')
                 {
                     isF = true;
                 }
             }
         }
         if (isX)
         {
             sizeF = this.graphics_.MeasureString(text, f, origin, this.typographicsFormat);
             sizeF.Width += this.roundOpFontSize(node, node.style_);
         }
         else if (isF)
         {
             sizeF = this.graphics_.MeasureString(text + "|", f, origin, this.typographicsFormat);
         }
         else
         {
             sizeF = this.graphics_.MeasureString(text, f, origin, this.typographicsFormat);
         }
     }
     width = sizeF.Width;
     height = sizeF.Height;
     FontFamilyInfo familyInfo = this.entityManager.GetFontFamilyInfo(f.Name);
     if (((familyInfo != null) && familyInfo.NeedCorrectX) && (((familyInfo.FontFamily != "ESSTIXFive") || (node.glyph == null)) || (node.glyph.Code != "0210F")))
     {
         if (f.Name == "ESSTIXEight")
         {
             xCorr = (int) Math.Round((double) (height * (((float) familyInfo.CorrectX) / 100f)));
             xCorr = Math.Max(xCorr, 2);
         }
         else
         {
             xCorr = (int) Math.Round((double) (height * (((float) familyInfo.CorrectX) / 100f)));
         }
     }
     if (((familyInfo != null) && familyInfo.NeedCorrectW) && (((familyInfo.FontFamily != "ESSTIXFive") || (node.glyph == null)) || (node.glyph.Code != "0210F")))
     {
         width += height * (((float) familyInfo.CorrectW) / 100f);
     }
     if ((familyInfo != null) && familyInfo.NeedCorrectY)
     {
         dy = height * (((float) familyInfo.CorrectY) / 100f);
     }
     float leading = 0f;
     if (styleAttributes == null)
     {
         leading = this.Leading(height, f, f.Style);
     }
     else
     {
         leading = this.Leading(height, f);
     }
     baseline = height - leading;
     if ((familyInfo != null) && familyInfo.NeedCorrectB)
     {
         baseline += height * (((float) familyInfo.CorrectB) / 100f);
     }
     if ((familyInfo != null) && familyInfo.NeedCorrectH)
     {
         height *= ((float) familyInfo.CorrectH) / 100f;
     }
     int h = 0;
     int b = 0;
     int w = 0;
     if ((node.type_.type == ElementType.Entity) && (node.glyph != null))
     {
         if (node.glyph.Code == "0222B")
         {
             baseline *= 1.1f;
         }
         else if (node.glyph.Code == "0222C")
         {
             width = 1.5f * width;
             baseline *= 1.1f;
         }
         else if (node.glyph.Code == "0222D")
         {
             width = 2f * width;
             baseline *= 1.1f;
         }
         else if (((node.glyph.Code == "0222E") || (node.glyph.Code == "02232")) || (node.glyph.Code == "02233"))
         {
             baseline *= 1.1f;
         }
         else if (node.glyph.Code == "0222F")
         {
             baseline *= 1.1f;
         }
         else if (node.glyph.Code == "02230")
         {
             baseline *= 1.1f;
         }
     }
     try
     {
         if ((((node.type_.type == ElementType.Entity) && (node.glyph != null)) && (this.IsParen(node.glyph.Code) && (familyInfo != null))) && (familyInfo.FontFamily == "Times New Roman"))
         {
             dy -= height * 0.0626953f;
         }
     }
     catch
     {
     }
     baseline -= MeasureBaseline(this.graphics_, "Times New Roman", f);
     h = (int) Math.Round((double) height);
     b = (int) Math.Round((double) baseline);
     w = (int) Math.Round((double) width);
     dY = (int) Math.Round((double) dy);
     node.box.Height = h;
     node.box.Baseline = b;
     node.box.Width = w;
     node.box.Dy = dY;
     node.box.Dx = xCorr;
 }
예제 #32
0
 private System.Drawing.Font MakeFont(Node node, int mode, Category category, int level, StyleAttributes styleAttributes)
 {
     string fontName;
     double level0Scale = 1;
     double level1Scale = 0.71;
     double level2Scale = 0.5;
     System.Drawing.FontStyle fontStyle = System.Drawing.FontStyle.Regular;
     if (styleAttributes != null)
     {
         level0Scale = styleAttributes.scale;
         if (styleAttributes.isBold)
         {
             fontStyle |= System.Drawing.FontStyle.Bold;
         }
         if (styleAttributes.isItalic)
         {
             fontStyle |= System.Drawing.FontStyle.Italic;
         }
         bool flag1 = styleAttributes.isUnderline;
     }
     switch (category)
     {
         case Category.BOLD:
         {
             fontStyle |= System.Drawing.FontStyle.Bold;
             break;
         }
         case Category.UNKNOWN:
         {
             if (((node != null) && (node.type_ != null)) && (node.type_.type == ElementType.Mi))
             {
                 if (styleAttributes == null)
                 {
                     fontStyle |= System.Drawing.FontStyle.Italic;
                     break;
                 }
                 if (styleAttributes.isTop)
                 {
                     fontStyle |= System.Drawing.FontStyle.Italic;
                 }
                 else if (((!styleAttributes.isNormal && !styleAttributes.isBold) && (!styleAttributes.isDoubleStruck && !styleAttributes.isFractur)) && ((!styleAttributes.isMonospace && !styleAttributes.isSans) && !styleAttributes.isScript))
                 {
                     fontStyle |= System.Drawing.FontStyle.Italic;
                 }
             }
             break;
         }
     }
     
     switch (category)
     {
         case Category.OPERATOR:
         case Category.NUMBER:
         case Category.UNKNOWN:
             if (styleAttributes != null)
             {
                 if (styleAttributes.isSans)
                 {
                     category = Category.SANSSERIF;
                 }
                 else if (styleAttributes.isMonospace)
                 {
                     category = Category.MONOSPACE;
                 }
                 else if (((styleAttributes.isFractur && (node != null)) &&
                           ((node.literalText != null) && (node.literalText.Length > 0))) &&
                          this.IsAlphaCaseless(node.literalText))
                 {
                     category = Category.FRACTUR;
                 }
                 else if (((styleAttributes.isDoubleStruck && (node != null)) &&
                           ((node.literalText != null) && (node.literalText.Length > 0))) &&
                          this.IsAlpha(node.literalText))
                 {
                     category = Category.DOUBLESTRUCK;
                 }
                 else if (((styleAttributes.isScript && (node != null)) &&
                           ((node.literalText != null) && (node.literalText.Length > 0))) &&
                          this.IsAlphaCaseless(node.literalText))
                 {
                     category = Category.SCRIPT;
                 }
             }
             break;
     }    
 
     switch (category)
     {
         case Category.SYMBOL:
         {
             switch (level)
             {
                 case 0:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Symbol", this.textSize);
                     }
                     if (styleAttributes == null)
                     {
                         return this.symbol0;
                     }
                     return new System.Drawing.Font("Symbol", (float) (this.textSize * level0Scale), fontStyle);
                 }
                 case 1:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Symbol", (float) (this.textSize * level1Scale));
                     }
                     if (styleAttributes == null)
                     {
                         return this.symbol1;
                     }
                     return new System.Drawing.Font("Symbol", (float) ((this.textSize * level1Scale) * level0Scale), fontStyle);
                 }
                 case 2:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Symbol", (float) (this.textSize * level2Scale));
                     }
                     if (styleAttributes == null)
                     {
                         return this.symbol2;
                     }
                     return new System.Drawing.Font("Symbol", (float) ((this.textSize * level2Scale) * level0Scale), fontStyle);
                 }
             }
             break;
         }
         case Category.BOLD:
         {
             switch (level)
             {
                 case 0:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Symbol", (float) (this.textSize * 1.5), System.Drawing.FontStyle.Bold);
                     }
                     if (styleAttributes == null)
                     {
                         return this.bold0;
                     }
                     return new System.Drawing.Font("Symbol", (float) ((this.textSize * 1.5) * level0Scale), fontStyle);
                 }
                 case 1:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Symbol", (float) ((this.textSize * 1.5) * level1Scale), System.Drawing.FontStyle.Bold);
                     }
                     if (styleAttributes == null)
                     {
                         return this.bold1;
                     }
                     return new System.Drawing.Font("Symbol", (float) (((this.textSize * 1.5) * level1Scale) * level0Scale), fontStyle);
                 }
                 case 2:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Symbol", (float) ((this.textSize * 1.5) * level2Scale), System.Drawing.FontStyle.Bold);
                     }
                     if (styleAttributes == null)
                     {
                         return this.bold2;
                     }
                     return new System.Drawing.Font("Symbol", (float) (((this.textSize * 1.5) * level2Scale) * level0Scale), fontStyle);
                 }
             }
             break;
         }
         
         case Category.OPERATOR:
         {
             switch (level)
             {
                 case 0:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Times New Roman", this.textSize);
                     }
                     if (styleAttributes == null)
                     {
                         return this.operator0;
                     }
                     return new System.Drawing.Font("Times New Roman", (float) (this.textSize * level0Scale), fontStyle);
                 }
                 case 1:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Times New Roman", (float) (this.textSize * level1Scale));
                     }
                     if (styleAttributes == null)
                     {
                         return this.operator1;
                     }
                     return new System.Drawing.Font("Times New Roman", (float) ((this.textSize * level1Scale) * level0Scale), fontStyle);
                 }
                 case 2:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Times New Roman", (float) (this.textSize * level2Scale));
                     }
                     if (styleAttributes == null)
                     {
                         return this.operator2;
                     }
                     return new System.Drawing.Font("Times New Roman", (float) ((this.textSize * level2Scale) * level0Scale), fontStyle);
                 }
             }
             break;
         }
         case Category.NUMBER:
         {
             switch (level)
             {
                 case 0:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Times New Roman", this.textSize);
                     }
                     if (styleAttributes == null)
                     {
                         return this.number0;
                     }
                     return new System.Drawing.Font("Times New Roman", (float) (this.textSize * level0Scale), fontStyle);
                 }
                 case 1:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Times New Roman", (float) (this.textSize * level1Scale));
                     }
                     if (styleAttributes == null)
                     {
                         return this.number1;
                     }
                     return new System.Drawing.Font("Times New Roman", (float) ((this.textSize * level1Scale) * level0Scale), fontStyle);
                 }
                 case 2:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Times New Roman", (float) (this.textSize * level2Scale));
                     }
                     if (styleAttributes == null)
                     {
                         return this.number2;
                     }
                     return new System.Drawing.Font("Times New Roman", (float) ((this.textSize * level2Scale) * level0Scale), fontStyle);
                 }
             }
             break;
         }
        
         case Category.UNKNOWN:
         {
             switch (level)
             {
                 case 0:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Times New Roman", this.textSize, System.Drawing.FontStyle.Italic);
                     }
                     if (styleAttributes == null)
                     {
                         return this.unknown0;
                     }
                     return new System.Drawing.Font("Times New Roman", (float) (this.textSize * level0Scale), fontStyle);
                 }
                 case 1:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Times New Roman", (float) (this.textSize * level1Scale), System.Drawing.FontStyle.Italic);
                     }
                     if (styleAttributes == null)
                     {
                         return this.unknown1;
                     }
                     return new System.Drawing.Font("Times New Roman", (float) ((this.textSize * level1Scale) * level0Scale), fontStyle);
                 }
                 case 2:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Times New Roman", (float) (this.textSize * level2Scale), System.Drawing.FontStyle.Italic);
                     }
                     if (styleAttributes == null)
                     {
                         return this.unknown2;
                     }
                     return new System.Drawing.Font("Times New Roman", (float) ((this.textSize * level2Scale) * level0Scale), fontStyle);
                 }
             }
             break;
         }
         
         case Category.SANSSERIF:
         {
             switch (level)
             {
                 case 0:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Arial", this.textSize);
                     }
                     if (styleAttributes == null)
                     {
                         return this.operator0;
                     }
                     return new System.Drawing.Font("Arial", (float) (this.textSize * level0Scale), fontStyle);
                 }
                 case 1:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Arial", (float) (this.textSize * level1Scale));
                     }
                     if (styleAttributes == null)
                     {
                         return this.operator1;
                     }
                     return new System.Drawing.Font("Arial", (float) ((this.textSize * level1Scale) * level0Scale), fontStyle);
                 }
                 case 2:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Arial", (float) (this.textSize * level2Scale));
                     }
                     if (styleAttributes == null)
                     {
                         return this.operator2;
                     }
                     return new System.Drawing.Font("Arial", (float) ((this.textSize * level2Scale) * level0Scale), fontStyle);
                 }
             }
             break;
         }
         case Category.FRACTUR:
         case Category.DOUBLESTRUCK:
         case Category.SCRIPT:
         {
             fontName = "";
             switch (category)
             {
                 case Category.FRACTUR:
                 {
                     fontName = "ESSTIXFifteen";
                     break;
                 }
                 case Category.DOUBLESTRUCK:
                 {
                     fontName = "ESSTIXFourteen";
                     break;
                 }
                 case Category.SCRIPT:
                 {
                     fontName = "ESSTIXThirteen";
                     break;
                 }
             }
             float sc = 1f;
             switch (level)
             {
                 case 0:
                 {
                     sc = (float) level0Scale;
                     break;
                 }
                 case 1:
                 {
                     sc = (float) (level1Scale*level0Scale);
                     break;
                 }
                 case 2:
                 {
                     sc = (float) (level2Scale*level0Scale);
                     break;
                 }
             }
             FontFamily family = null;
             if (this.fonts_ != null)
             {
                 family = this.fonts_.Get(fontName);
             }
             if (family != null)
             {
                 return new System.Drawing.Font(family, this.textSize*sc, fontStyle);
             }
             return new System.Drawing.Font(fontName, this.textSize*sc, fontStyle);
         }
         case Category.MONOSPACE:
         {
             switch (level)
             {
                 case 0:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Courier New", this.textSize, System.Drawing.FontStyle.Italic);
                     }
                     if (styleAttributes == null)
                     {
                         return this.mono0;
                     }
                     return new System.Drawing.Font("Courier New", (float) (this.textSize * level0Scale), fontStyle);
                 }
                 case 1:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Courier New", (float) (this.textSize * level1Scale), System.Drawing.FontStyle.Italic);
                     }
                     if (styleAttributes == null)
                     {
                         return this.mono1;
                     }
                     return new System.Drawing.Font("Courier New", (float) ((this.textSize * level1Scale) * level0Scale), fontStyle);
                 }
                 case 2:
                 {
                     if (mode == 1)
                     {
                         return new System.Drawing.Font("Courier New", (float) (this.textSize * level2Scale), System.Drawing.FontStyle.Italic);
                     }
                     if (styleAttributes == null)
                     {
                         return this.mono2;
                     }
                     return new System.Drawing.Font("Courier New", (float) ((this.textSize * level2Scale) * level0Scale), fontStyle);
                 }
             }
             break;
         }
         
         case Category.GLYPH:
         {
             switch (level)
             {
                 case 0:
                 {
                     if (mode != 1)
                     {
                         return new System.Drawing.Font(node.fontFamily, (float) (this.textSize * level0Scale), fontStyle);
                     }
                     break;
                 }
                 case 1:
                 {
                     if (mode != 1)
                     {
                         return new System.Drawing.Font(node.fontFamily, (float) ((this.textSize * level1Scale) * level0Scale), fontStyle);
                     }
                     break;
                 }
                 case 2:
                 {
                     if (mode != 1)
                     {
                         return new System.Drawing.Font(node.fontFamily, (float) ((this.textSize * level2Scale) * level0Scale), fontStyle);
                     }
                     break;
                 }
             }
             break;
         }
     }
     
     return new System.Drawing.Font("Symbol", this.textSize);
 }