Esempio n. 1
0
        private static bool StartNewSpan(StringBuilder html,
                                         String writingSystemId,
                                         bool boldText,
                                         bool underline,
                                         int fontSizeBoost)
        {
            if (!WritingSystems.Contains(writingSystemId))
            {
                return(false);
                //that ws isn't actually part of our configuration, so can't get a special font for it
            }
            IWritingSystemDefinition ws = (IWritingSystemDefinition)WritingSystems.Get(writingSystemId);
            Font   font          = WritingSystemInfo.CreateFont(ws);
            float  fontSize      = font.Size + fontSizeBoost;
            String lang          = ws.Bcp47Tag.IndexOf('-') == -1 ? ws.Bcp47Tag : ws.Bcp47Tag.Substring(0, ws.Bcp47Tag.IndexOf('-'));
            var    formattedSpan = string.Format(
                "<span lang='{5}' style='font-family:{0}; font-size:{1}pt;font-weight:{2};font-style:{3};text-decoration:{4}'>",
                font.Name,
                fontSize.ToString(),
                boldText ? "bold": "normal",
                italicsOn ? "italic" : "normal",
                underline ? "underline" : "none",
                lang);

            html.Append(formattedSpan);
            AddFontFamily(font.Name);
            return(true);
        }
 public void SensitiveToFontSize()
 {
     SetKeyAndShow("3");
     //the +3 fudge here is because the actual height of the
     //inner text box is something less than the Font's GetHeight
     Assert.Greater(_control.Height + 3, WritingSystemInfo.CreateFont(_ws).GetHeight());
 }
Esempio n. 3
0
 private void ComputeItemHeight()
 {
     ItemHeight = (int)(Math.Ceiling(WritingSystemInfo.CreateFont(_formWritingSystem).GetHeight()));
     if (_meaningWritingSystem != null)
     {
         ItemHeight += (int)(Math.Ceiling(WritingSystemInfo.CreateFont(_meaningWritingSystem).GetHeight()));
         ItemHeight += 10;                 //margin
     }
 }
Esempio n. 4
0
 public Font GetFontOfSemanticDomainField()
 {
     if (_semanticDomainWritingSystem == null)             // just in case there is no WS for the semDom field (not likely)
     {
         _semanticDomainWritingSystem = new WritingSystemDefinition("qaa");
         _semanticDomainWritingSystem.DefaultFontName = "Microsoft Sans Serif";
     }
     return(WritingSystemInfo.CreateFont(_semanticDomainWritingSystem));
 }
Esempio n. 5
0
        // Called from the ItemDrawer routine from the data source to add the item to the
        // html being built by CreateHtmlFromItems
        public void ItemToHtml(string word, int index, bool useFormWS, Color textColor)
        {
            IWritingSystemDefinition ws = useFormWS ? FormWritingSystem : MeaningWritingSystem;
            Font   font  = WritingSystemInfo.CreateFont(ws);
            String entry = String.IsNullOrEmpty(word) ? "&nbsp;" : System.Security.SecurityElement.Escape(word);
            String subId = useFormWS ? "-1" : "-2";
            String id    = index.ToString() + subId;

            _itemHtml.AppendFormat("<li id='{2}' {5} style='font-family:{3}; font-size:{4}pt;' onclick=\"fireEvent('selectChanged','{0}');\">{1}</li>",
                                   index.ToString(), entry, id, font.Name, font.Size, GetLanguageHtml(ws));
        }
Esempio n. 6
0
        public void CreateFont_WithFontName_NameSetToFontName()
        {
            var ws = new WritingSystemDefinition
            {
                DefaultFontName = FontFamily.GenericSerif.Name
            };

            // Assert the precondition
            Assert.AreNotEqual(FontFamily.GenericSansSerif.Name, ws.DefaultFontName);
            // Assert the test
            Assert.AreEqual(WritingSystemInfo.CreateFont(ws).Name, ws.DefaultFontName);
        }
Esempio n. 7
0
        private static string MakeFontTable()
        {
            var rtf = new StringBuilder(@"{\fonttbl");
            int i   = 0;

            foreach (var ws in WritingSystems.AllWritingSystems)
            {
                rtf.Append(@"\f" + i + @"\fnil\fcharset0" + " " + WritingSystemInfo.CreateFont(ws).FontFamily.Name +
                           ";");
                i++;
            }
            rtf.Append("}");
            return(rtf.ToString());
        }
Esempio n. 8
0
        private static string SwitchToWritingSystem(string writingSystemId, int sizeBoost)
        {
            if (!WritingSystems.Contains(writingSystemId))
            {
                return("");
                //that ws isn't actually part of our configuration, so can't get a special font for it
            }
            IWritingSystemDefinition writingSystem = (IWritingSystemDefinition)WritingSystems.Get(writingSystemId);
            string rtf      = @"\f" + GetFontNumber(writingSystem);
            int    fontSize = Convert.ToInt16((sizeBoost + WritingSystemInfo.CreateFont(writingSystem).SizeInPoints) * 2);

            rtf += @"\fs" + fontSize + " ";
            return(rtf);
        }
Esempio n. 9
0
        private void DrawToolTip(object sender, DrawToolTipEventArgs e)
        {
            e.DrawBackground();
            e.DrawBorder();
            TextFormatFlags flags = TextFormatFlags.Default | TextFormatFlags.Left |
                                    TextFormatFlags.VerticalCenter;

            if (_writingSystem != null && WritingSystem.RightToLeftScript)
            {
                flags |= TextFormatFlags.RightToLeft;
            }
            TextRenderer.DrawText(e.Graphics,
                                  e.ToolTipText,
                                  WritingSystemInfo.CreateFont(_writingSystem),
                                  e.Bounds,
                                  tooltip.ForeColor,
                                  flags);
        }
Esempio n. 10
0
 public SingleOptionControl(IValueHolder <string> optionRef, OptionsList list, string nameForLogging, IWritingSystemDefinition preferredWritingSystem, IServiceProvider serviceProvider)
 {
     AutoSize                = true;
     AutoSizeMode            = AutoSizeMode.GrowAndShrink;
     _list                   = list;
     _nameForLogging         = nameForLogging;
     _preferredWritingSystem = preferredWritingSystem;
     _control                = serviceProvider.GetService(typeof(IWeSayComboBox)) as IWeSayComboBox;
     InitializeComponent();
     _control.AutoCompleteMode   = AutoCompleteMode.Append;
     _control.AutoCompleteSource = AutoCompleteSource.ListItems;
     _control.Sorted             = false;
     _control.MaxDropDownItems   = 100;
     _control.WritingSystem      = _preferredWritingSystem;
     _control.Font   = WritingSystemInfo.CreateFont(_preferredWritingSystem);
     _control.Height = WritingSystemInfo.CreateFont(_preferredWritingSystem).Height + 10;
     BuildBoxes(optionRef);
 }
Esempio n. 11
0
        private void AddFontFamily(IWritingSystemDefinition ws)
        {
            if (ws != null)
            {
                Font   font       = WritingSystemInfo.CreateFont(ws);
                string fontFamily = font.Name;
                var    match      = _fontFamilies.FirstOrDefault(stringToCheck => stringToCheck.Equals(fontFamily));

                if (match == null)
                {
                    _fontFamilies.Add(fontFamily);
                    _fontFamiliesStyle.AppendLine("@font-face {");
                    _fontFamiliesStyle.AppendFormat("    font-family: \"{0}\";\n", fontFamily);
                    _fontFamiliesStyle.AppendFormat("    src: local(\"{0}\");\n", fontFamily);
                    _fontFamiliesStyle.AppendLine("}");
                }
            }
        }
Esempio n. 12
0
        private String SelectStyle()
        {
            String justification = "left";

            if (_writingSystem != null && WritingSystem.RightToLeftScript)
            {
                justification = "right";
            }
            Font font = WritingSystemInfo.CreateFont(_writingSystem);

            return(String.Format("min-height:15px; width=30em; font-family:{0}; font-size:{1}pt; text-align:{2}; font-weight:{3}; background:{4}; width:{5}",
                                 font.Name,
                                 font.Size,
                                 justification,
                                 Bold ? "bold" : "normal",
                                 System.Drawing.ColorTranslator.ToHtml(BackColor),
                                 this.Width));
        }
Esempio n. 13
0
        private Size MeasureItemText(string text)
        {
            TextFormatFlags flags = TextFormatFlags.Default | TextFormatFlags.Left;

            if (_writingSystem != null && WritingSystem.RightToLeftScript)
            {
                flags |= TextFormatFlags.RightToLeft;
            }
            int maxWidth = Screen.GetWorkingArea(this).Width;

            using (Graphics g = Graphics.FromHwnd(Handle))
            {
                return(TextRenderer.MeasureText(g,
                                                text,
                                                WritingSystemInfo.CreateFont(_writingSystem),
                                                new Size(maxWidth, int.MaxValue),
                                                flags));
            }
        }
Esempio n. 14
0
        public void ListCompleted()
        {
            _initialSelectLoad = false;
            Font font = WritingSystemInfo.CreateFont(_writingSystem);

            var html = new StringBuilder();

            html.Append("<!DOCTYPE html>");
            html.Append("<html><head><meta charset=\"UTF-8\">");
            html.Append("<style>");
            html.Append("@font-face {");
            html.AppendFormat("    font-family: \"{0}\";\n", font.Name);
            html.AppendFormat("    src: local(\"{0}\");\n", font.Name);
            html.Append("}");
            html.Append("</style>");
            html.Append("<script type='text/javascript'>");
            html.Append(" function fireEvent(name, data)");
            html.Append(" {");
            html.Append("   var event = new MessageEvent(name, {'data' : data});");
            html.Append("   document.dispatchEvent(event);");
            html.Append(" }");
            html.Append("</script>");
            html.Append("</head>");
            html.AppendFormat("<body {2} style='background:{0}; width:{1}' id='mainbody'>",
                              System.Drawing.ColorTranslator.ToHtml(Color.White),
                              this.Width,
                              GetLanguageHtml(_writingSystem));
            html.Append("<select size='10' id='main' style='" + SelectStyle() + "' onchange=\"fireEvent('selectChanged','changed');\">");
            // The following line is removed at this point and done later as a change to the inner
            // html because otherwise the browser blows up because of the length of the
            // navigation line.  Leaving this and this comment in as a warning to anyone who
            // may be tempted to try the same thing.
            // html.Append(_itemHtml);

            // Adding a one character option instead to get an accurate height for the font
            html.Append("<option id='optionElement' value=\" \">&nbsp</option>");
            html.Append("</select></body></html>");
            SetHtml(html.ToString());
        }
Esempio n. 15
0
        public void CreateFont_Default_GetFontSizeIs12()
        {
            var ws = new WritingSystemDefinition();

            Assert.AreEqual(12, WritingSystemInfo.CreateFont(ws).Size);
        }
Esempio n. 16
0
        public void CreateFont_Default_GetReturnsGenericSansSerif()
        {
            var ws = new WritingSystemDefinition();

            Assert.AreEqual(FontFamily.GenericSansSerif, WritingSystemInfo.CreateFont(ws).FontFamily);
        }
Esempio n. 17
0
        private void SetText(string s)
        {
            s = System.Security.SecurityElement.Escape(s);
            String justification  = "left";
            String multiLineStyle = "";
            String background     = "#FFFFFF";

            if (_writingSystem != null && WritingSystem.RightToLeftScript)
            {
                justification = "right";
            }

            String editable = "true";

            if (ReadOnly)
            {
                editable   = "false";
                background = System.Drawing.ColorTranslator.ToHtml(BackColor);
            }

            if (Multiline)
            {
                multiLineStyle = "word-wrap:break-word; ";
            }
            else
            {
                multiLineStyle = "white-space:nowrap; ";
            }
            Font font = WritingSystemInfo.CreateFont(_writingSystem);
            var  html = new StringBuilder("<html>");

            html.AppendLine("<head>");
            html.AppendLine("<meta charset=\"UTF-8\">");
            html.AppendLine("<style>");
            html.AppendLine("@font-face {");
            html.AppendFormat("    font-family: \"{0}\";\n", font.Name);
            html.AppendFormat("    src: local(\"{0}\");\n", font.Name);
            html.AppendLine("}");
            html.AppendLine("</style>");
            html.AppendLine("</head>");
            html.AppendFormat("<body style='background:{1}' id='mainbody' {0}>", GetLanguageHtml(_writingSystem), background);
            html.AppendFormat("<div style='min-height:15px; font-family:{0}; font-size:{1}pt; text-align:{3} background:{5}; color:{6}; {7}' id='main' name='textArea' contentEditable='{4}'>{2}</div>",
                              font.Name, font.Size.ToString(), s, justification, editable, System.Drawing.ColorTranslator.ToHtml(BackColor), System.Drawing.ColorTranslator.ToHtml(ForeColor), multiLineStyle);
            html.AppendLine("</body>");
            html.AppendLine("</html>");
            if (!_browserIsReadyToNavigate)
            {
                _pendingHtmlLoad = html.ToString();
            }
            else
            {
                if (!_keyPressed)
                {
#if DEBUG
                    //Debug.WriteLine ("SetText: " + html);
#endif
                    _browser.LoadHtml(html.ToString());
                }
                _keyPressed = false;
            }
        }