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; }
private void ButtonAddFontClick(object sender, EventArgs e) { CSSFontFamily newFamily = new CSSFontFamily(); CSSFontSettings.Fonts.Add(newFamily.Name, newFamily); listViewFonts.Items.Add(newFamily.Name); RefreshData(); EditFontFamily(newFamily.Name); }
private void ReadFonts(XmlReader reader) { _fontFamilies.Clear(); while (!reader.EOF) { if (reader.IsStartElement()) { switch (reader.Name) { case CSSFontFamily.FontFamilyElementName: var fontFamily = new CSSFontFamily(); fontFamily.ReadXml(reader.ReadSubtree()); _fontFamilies.Add(fontFamily); break; } } reader.Read(); } }
public void SetupDefaults() { _transliterateFileName = false; _addFB2Info = true; _addSeqToTitle = true; _sequenceFormat = @"%bt% %sa.l%-%sn%"; _noSequenceFormat = @"%bt% (%sf.l%)"; _noSeriesFormat = @"%bt%"; _authorFormat = @"%f.c% %m.c% %l.c% %n.c:b%"; _fileAsFormat = @"%l.c% %f.c%"; _skipAboutPage = false; _ignoreTitle = IgnoreInfoSourceOptions.IgnoreNothing; _ignoreAuthors = IgnoreInfoSourceOptions.IgnoreNothing; _ignoreTranslators = IgnoreInfoSourceOptions.IgnoreNothing; _ignoreGenres = IgnoreInfoSourceOptions.IgnoreNothing; _decorateFontNames = true; _transliterationSettings.CopyFrom(new TransliterationSettingsImp {Mode = TranslitModeEnum.None}); _fonts.FontFamilies.Clear(); _fonts.CssElements.Clear(); CSSFontFamily family = new CSSFontFamily() { Name = @"LiberationSerif" }; CSSFont font1 = new CSSFont { FontStyle = FontStylesEnum.Normal, FontVariant = FontVaiantEnum.Normal, FontWidth = FontBoldnessEnum.B400, FontStretch = FontStretch.Normal }; font1.Sources.Add(new FontSource() { Type = SourceTypes.Embedded, Format = FontFormat.Unknown, Location = @"%ResourceFolder%\Fonts/LiberationSerif-Regular.ttf" }); family.Fonts.Add(font1); CSSFont font2 = new CSSFont { FontStyle = FontStylesEnum.Italic, FontVariant = FontVaiantEnum.Normal, FontWidth = FontBoldnessEnum.B400, FontStretch = FontStretch.Normal }; font2.Sources.Add(new FontSource() { Type = SourceTypes.Embedded, Format = FontFormat.Unknown, Location = @"%ResourceFolder%\Fonts/LiberationSerif-Italic.ttf" }); family.Fonts.Add(font2); CSSFont font3 = new CSSFont { FontStyle = FontStylesEnum.Normal, FontVariant = FontVaiantEnum.Normal, FontWidth = FontBoldnessEnum.B700, FontStretch = FontStretch.Normal }; font3.Sources.Add(new FontSource() { Type = SourceTypes.Embedded, Format = FontFormat.Unknown, Location = @"%ResourceFolder%\Fonts/LiberationSerif-Bold.ttf" }); family.Fonts.Add(font3); CSSFont font4 = new CSSFont { FontStyle = FontStylesEnum.Italic, FontVariant = FontVaiantEnum.Normal, FontWidth = FontBoldnessEnum.B700, FontStretch = FontStretch.Normal }; font4.Sources.Add(new FontSource() { Type = SourceTypes.Embedded, Format = FontFormat.Unknown, Location = @"%ResourceFolder%\Fonts/LiberationSerif-BoldItalic.ttf" }); family.Fonts.Add(font4); _fonts.FontFamilies.Add(family); CSSStylableElement css1 = new CSSStylableElement() { Name = "body" }; css1.AssignedFontFamilies.Add(family.Name); _fonts.CssElements.Add(css1); CSSStylableElement css2 = new CSSStylableElement() { Name = "code" }; css2.AssignedFontFamilies.Add(family.Name); _fonts.CssElements.Add(css2); CSSStylableElement css3 = new CSSStylableElement() { Name = "epub" }; css3.AssignedFontFamilies.Add(family.Name); _fonts.CssElements.Add(css3); }
private void ReadFonts(XmlReader reader) { _fontFamilies.Clear(); while(!reader.EOF) { if (reader.IsStartElement()) { switch (reader.Name) { case CSSFontFamily.FontFamilyElementName: var fontFamily = new CSSFontFamily(); fontFamily.ReadXml(reader.ReadSubtree()); _fontFamilies.Add(fontFamily); break; } } reader.Read(); } }
/// <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; }
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; }