Пример #1
0
        public void StoreTo(IEPubFontSettings settings)
        {
            settings.FontFamilies.Clear();
            settings.CssElements.Clear();
            foreach (var cssFontFamily in _fonts.Keys)
            {
                CSSFontFamily newFamily = new CSSFontFamily();
                newFamily.CopyFrom(_fonts[cssFontFamily]);
                newFamily.DecorationId = _loadedDecoration;
                settings.FontFamilies.Add(newFamily);
            }

            foreach (var elementName in _elements.Keys)
            {
                foreach (var elementClass in _elements[elementName].Keys)
                {
                    var item = new CSSStylableElement {
                        Name = elementName, Class = elementClass
                    };
                    foreach (var fontFamily in _elements[elementName][elementClass])
                    {
                        item.AssignedFontFamilies.Add(fontFamily.Name);
                    }
                    settings.CssElements.Add(item);
                }
            }
            _storageSettings = settings;
        }
Пример #2
0
 private void ReadCSSElements(XmlReader reader)
 {
     _cssElements.Clear();
     while (!reader.EOF)
     {
         if (reader.IsStartElement())
         {
             switch (reader.Name)
             {
             case CSSStylableElement.CSSStylableElementName:
                 var cssElement = new CSSStylableElement();
                 cssElement.ReadXml(reader.ReadSubtree());
                 _cssElements.Add(cssElement);
                 break;
             }
         }
         reader.Read();
     }
 }
Пример #3
0
        /// <summary>
        /// Load settings into a workable helper class structure
        /// </summary>
        /// <param name="settings">settings to load</param>
        /// <param name="decoration">decoration to be added to family font names</param>
        public void Load(IEPubFontSettings settings, string decoration)
        {
            // Copy all font families
            _fonts.Clear();
            _fontFiles.Clear();
            MakeDecorationValid(ref decoration);
            foreach (var cssFontFamily in settings.FontFamilies)
            {
                CSSFontFamily newFamily = new CSSFontFamily();
                newFamily.CopyFrom(cssFontFamily);
                newFamily.DecorationId = decoration;
                _fonts.Add(newFamily.Name, newFamily);
                foreach (var cssFont in newFamily.Fonts)                                                           // go over all fonts in family
                {
                    foreach (var fontSource in cssFont.Sources)                                                    // and all sources of the fonts in font family
                    {
                        if (fontSource.Type == SourceTypes.Embedded)                                               // if font is embedded font
                        {
                            string locationKey          = fontSource.Location.ToLower();                           // one case good for comparison
                            bool   needToUpdateLocation = false;
                            if (!string.IsNullOrEmpty(_resourcePath) && locationKey.Contains(MacroMask.ToLower())) // in case we need to update resource path
                            {
                                needToUpdateLocation = true;
                            }
                            else if (string.IsNullOrEmpty(_resourcePath))
                            {
                                _resourcePath        = ResourceLocator.Instance.GetResourcesPath();
                                needToUpdateLocation = true;
                            }

                            if (needToUpdateLocation)
                            {
                                locationKey = locationKey.Replace(MacroMask.ToLower(), _resourcePath);
                            }

                            if (!_fonts.ContainsKey(locationKey)) // if key/location not present - add it
                            {
                                _fontFiles.Add(locationKey, new List <ICSSFont>());
                            }
                            _fontFiles[locationKey].Add(cssFont); // save reference to the font object
                        }
                    }
                }
            }

            // now fill the list with pointers to the font families instead of names
            _elements.Clear();
            foreach (var element in settings.CssElements)
            {
                CSSStylableElement newElement = new CSSStylableElement();
                newElement.CopyFrom(element);
                if (!_elements.ContainsKey(element.Name))                                           // if key not present
                {
                    _elements.Add(element.Name, new Dictionary <string, List <ICSSFontFamily> >()); // add
                }
                _elements[element.Name].Add(element.Class, new List <ICSSFontFamily>());            // reserve place for new list
                // now fill the list with pointers to the font families instead of names
                foreach (var assignedFontFamily in element.AssignedFontFamilies)
                {
                    string updatedFamilyName = CSSFontFamily.MakeDecoratedName(assignedFontFamily, decoration);
                    if (_fonts.ContainsKey(updatedFamilyName))
                    {
                        _elements[element.Name][element.Class].Add(_fonts[updatedFamilyName]);
                    }
                }
            }

            _storageSettings  = settings;
            _loadedDecoration = decoration;
        }