Example #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;
        }
Example #2
0
        public void CopyFrom(IEPubFontSettings ePubFontSettings)
        {
            if (ePubFontSettings == null)
            {
                throw new ArgumentNullException("ePubFontSettings");
            }
            _fontFamilies.Clear();
            foreach (var element in ePubFontSettings.FontFamilies)
            {
                _fontFamilies.Add(element);
            }

            _cssElements.Clear();
            foreach (var element in ePubFontSettings.CssElements)
            {
                _cssElements.Add(element);
            }
        }
Example #3
0
        public void CopyFrom(IEPubFontSettings ePubFontSettings)
        {
            if (ePubFontSettings == null)
            {
                throw new ArgumentNullException("ePubFontSettings");
            }
            _fontFamilies.Clear();
            foreach (var element in ePubFontSettings.FontFamilies)
            {
                _fontFamilies.Add(element);
            }

            _cssElements.Clear();
            foreach (var element in ePubFontSettings.CssElements)
            {
                _cssElements.Add(element);
            }
        }
Example #4
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;
        }
Example #5
0
 /// <summary>
 /// Assign ePub fonts from set of Fonts settings
 /// </summary>
 /// <param name="fonts">font settings to use</param>
 /// <param name="resourcesPath">path to program's "resources"</param>
 /// <param name="decorateFontNames">add or not random decoration to the font names</param>
 public void SetEPubFonts(IEPubFontSettings fonts, string resourcesPath, bool decorateFontNames)
 {
     _fontSettings.ResourceMask = resourcesPath;
     _fontSettings.Load(fonts, decorateFontNames ? _bookInformation.Identifiers[0].IdentifierName : string.Empty);
 }
Example #6
0
 /// <summary>
 /// Assign ePub fonts from set of Fonts settings
 /// </summary>
 /// <param name="fonts">font settings to use</param>
 /// <param name="resourcesPath">path to program's "resources"</param>
 /// <param name="decorateFontNames">add or not random decoration to the font names</param>
 public void SetEPubFonts(IEPubFontSettings fonts, string resourcesPath, bool decorateFontNames)
 {
     _fontSettings.ResourceMask = resourcesPath;
     _fontSettings.Load(fonts, decorateFontNames ? _bookInformation.Identifiers[0].IdentifierName : string.Empty);
 }
        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;
        }
        /// <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;
        }