public DecoratedTextBoxEditModePropertyControl()
		{
			_fontFamilies = new FontFamilyCollection();

			_colorControl = AddColorControl();

			BindFontFamilyDropDown();

			BindFotnSizeDropDown();

			BindAlignmentDictionary();

			BindStyleDictionary();

			FillControl(true);

			InitEvents();
		}
예제 #2
0
        /// <summary>
        /// Detects font sets by analyzing all "text-face-name" properties.
        /// </summary>
        /// <param name="definitions"></param>
        /// <param name="env"></param>
        public static void SetFontSets(Map map, List <CartoDefinition> definitions, Env env, ICartoTranslator cartoTranslator)
        {
            List <FontSet> fontSets = new List <FontSet>();
            Dictionary <string, FontSet> dictFontSets = new Dictionary <string, FontSet>();

            using (FontFamilyCollection fontCollection = FontUtility.GetFontFamilyCollection())
            {
                List <FontFamilyTypeface> typeFaces         = new List <FontFamilyTypeface>();
                List <string>             notFoundFontNames = new List <string>();

                int fontSetCounter = 0;

                foreach (CartoDefinition def in definitions)
                {
                    foreach (CartoRule rule in def.Rules)
                    {
                        if (rule.Name == "text-face-name" || rule.Name == "shield-face-name")
                        {
                            try
                            {
                                Value  value        = rule.Value as Value;
                                string strFontNames = value.Evaluate(env).ToString().Replace("\"", "");

                                FontSet fontSet = null;
                                if (_dictFontSets.TryGetValue(strFontNames, out fontSet))
                                {
                                    if (!fontSets.Contains(fontSet))
                                    {
                                        fontSets.Add((FontSet)fontSet.Clone());
                                        dictFontSets.Add(strFontNames, fontSet);
                                    }

                                    continue;
                                }

                                string[] fontNames = strFontNames.Split(',');

                                for (int i = 0; i < fontNames.Length; i++)
                                {
                                    fontNames[i] = fontNames[i].Trim('\'').Trim();
                                }

                                typeFaces.Clear();

                                foreach (string fontName in fontNames)
                                {
                                    string             fName    = fontName.Replace(" ", "");
                                    FontFamilyTypeface typeFace = null;

                                    foreach (MapSurfer.Drawing.FontFamily fontFamily in fontCollection.FontFamilies)
                                    {
                                        if (typeFace != null)
                                        {
                                            break;
                                        }

                                        foreach (FontFamilyTypeface fft in fontFamily.GetTypefaces())
                                        {
                                            foreach (string faceName in fft.FaceNames)
                                            {
                                                string fullName = (fontFamily.Name + faceName).Replace(" ", "");

                                                if (string.Equals(fName, fullName, StringComparison.OrdinalIgnoreCase))
                                                {
                                                    typeFace = fft;
                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    // We were not able to find appropriate type face
                                    if (typeFace == null)
                                    {
                                        if (!notFoundFontNames.Contains(fontName))
                                        {
                                            notFoundFontNames.Add(fontName);
                                            LogFactory.WriteLogEntry(Logger.Default, string.Format("Unable to find font face(s) for '{0}'", fontName), LogEntryType.Warning);
                                        }
                                    }
                                    else
                                    {
                                        typeFaces.Add(typeFace);
                                    }
                                }

                                string fontSetName = "fontset-" + fontSetCounter.ToString();

                                if (typeFaces.Count > 0)
                                {
                                    FontSet fs = new FontSet(fontSetName, typeFaces[0].Style, typeFaces[0].Weight);
                                    foreach (FontFamilyTypeface fft in typeFaces)
                                    {
                                        fs.FontNames.Add(fft.FontFamily.Name);
                                    }

                                    fontSets.Add((FontSet)fs.Clone());
                                    _dictFontSets.TryAdd(strFontNames, fs);
                                    dictFontSets.Add(strFontNames, fs);

                                    fontSetCounter++;
                                }
                            }
                            catch
                            { }
                        }
                    }
                }
            }

            if (fontSets.Count > 0)
            {
                map.FontSets.AddRange(fontSets);
            }

            cartoTranslator.FontSets = dictFontSets;
        }