Example #1
0
        /// <summary>
        /// Add CSS "target" section ( like p , body , etc) to CSS file
        /// </summary>
        /// <param name="item"></param>
        public void AddTarget(BaseCSSItem item)
        {
            // If it's a new item just add it
            int sameItemPos = _targets.FindIndex(x => x.Name.ToLower() == item.Name.ToLower());

            if (sameItemPos == -1)
            {
                _targets.Add(item);
            }
            else
            {
                // if similar item already exists we copy parameters
                foreach (var parameter in item.Parameters)
                {
                    // but copy only in case that it's new parameters, ignore same
                    if (!_targets[sameItemPos].Parameters.ContainsKey(parameter.Key))
                    {
                        _targets[sameItemPos].Parameters.Add(parameter.Key, parameter.Value);
                    }
                    else if (_targets[sameItemPos].Parameters[parameter.Key].ToString().ToLower() != parameter.Value.ToString().ToLower())
                    {
                        string old = (string)_targets[sameItemPos].Parameters[parameter.Key];
                        _targets[sameItemPos].Parameters[parameter.Key] = string.Format("{0}, {1}", old, parameter.Value);

                        //    Logger.log.ErrorFormat("CSS values conflict for parameter \"{0}\" ",parameter.Key);
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// Loads items from another CSS file
 /// </summary>
 /// <param name="fileName">file to load</param>
 /// <param name="add">selects if new data should be added to current "in memory" data or replace it</param>
 public void Load(string fileName, bool add)
 {
     if (!add)
     {
         _targets.Clear();
         _fonts.Clear();
     }
     using (var textReader = File.OpenText(fileName))
     {
         string line;
         var    elementString = new StringBuilder();
         while ((line = textReader.ReadLine()) != null)
         {
             if (!string.IsNullOrEmpty(line))
             {
                 line = line.Trim();
                 int endPosition   = line.IndexOf('}');
                 int startPosition = 0;
                 while (endPosition != -1)
                 {
                     elementString.Append(line.Substring(startPosition, endPosition - startPosition + 1));
                     BaseCSSItem cssItem = new BaseCSSItem();
                     try
                     {
                         cssItem.Parse(elementString.ToString());
                         AddTarget(cssItem);
                     }
                     catch (Exception ex)
                     {
                         Logger.Log.Error(ex);
                     }
                     elementString.Remove(0, elementString.Length);
                     startPosition = endPosition + 1;
                     endPosition   = line.IndexOf('}', startPosition);
                 }
                 elementString.Append(line.Substring(startPosition, line.Length - startPosition));
             }
         }
     }
 }
Example #3
0
 /// <summary>
 /// Loads items from another CSS file
 /// </summary>
 /// <param name="fileName">file to load</param>
 /// <param name="add">selects if new data should be added to current "in memory" data or replace it</param>
 public void Load(string fileName, bool add)
 {
     if (!add)
     {
         _targets.Clear();
         _fonts.Clear();
     }
     using (var textReader = File.OpenText(fileName))
     {
         string line;
         var elementString = new StringBuilder();
         while ((line = textReader.ReadLine()) != null)
         {
             if (!string.IsNullOrEmpty(line))
             {
                 line = line.Trim();
                 int endPosition = line.IndexOf('}');
                 int startPosition = 0;
                 while (endPosition != -1)
                 {
                     elementString.Append(line.Substring(startPosition, endPosition - startPosition+1));
                     BaseCSSItem cssItem = new BaseCSSItem();
                     try
                     {
                         cssItem.Parse(elementString.ToString());
                         AddTarget(cssItem);
                     }
                     catch (Exception ex)
                     {
                         Logger.Log.Error(ex);
                     }
                     elementString.Remove(0, elementString.Length);
                     startPosition = endPosition+1;
                     endPosition = line.IndexOf('}', startPosition);
                 }
                 elementString.Append(line.Substring(startPosition,line.Length - startPosition));
             }
         }
     }
 }
Example #4
0
        private void AddCssElementsToCSS(Dictionary<string, Dictionary<string, List<ICSSFontFamily>>> cssElements)
        {
            // Now add the elements
            foreach (var elementName in cssElements.Keys)
            {
                foreach (var elementClass in cssElements[elementName].Keys)
                {
                    var cssItem = new BaseCSSItem();
                    var sb = new StringBuilder();
                    sb.Append(elementName);
                    if (!string.IsNullOrEmpty(elementClass))
                    {
                        sb.AppendFormat(".{0}",elementClass);
                    }
                    cssItem.Name = sb.ToString();

                    // now build a list of fonts
                    sb.Clear();
                    int counter = 0;
                    if (elementClass != null)
                    {
                        foreach (var fontFamily in cssElements[elementName][elementClass])
                        {
                            sb.AppendFormat("\"{0}\"", fontFamily.Name);
                            if (counter != 0)
                            {
                                sb.Append(", ");
                            }
                            counter++;
                        }
                    }
                    cssItem.Parameters.Add("font-family", sb.ToString());
                    _mainCss.AddTarget(cssItem);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Add CSS "target" section ( like p , body , etc) to CSS file
        /// </summary>
        /// <param name="item"></param>
        public void AddTarget(BaseCSSItem item)
        {
            // If it's a new item just add it
            int sameItemPos = _targets.FindIndex(x => x.Name.ToLower() == item.Name.ToLower());
            if ( sameItemPos == -1)
            {
                _targets.Add(item);
            }
            else
            {
                // if similar item already exists we copy parameters
                foreach (var parameter in item.Parameters)
                {
                    // but copy only in case that it's new parameters, ignore same
                    if (!_targets[sameItemPos].Parameters.ContainsKey(parameter.Key))
                    {
                        _targets[sameItemPos].Parameters.Add(parameter.Key,parameter.Value);
                    }
                    else if (_targets[sameItemPos].Parameters[parameter.Key].ToString().ToLower() != parameter.Value.ToString().ToLower())
                    {
                        string old = (string)_targets[sameItemPos].Parameters[parameter.Key];
                        _targets[sameItemPos].Parameters[parameter.Key] = string.Format("{0}, {1}", old, parameter.Value);

                    //    Logger.log.ErrorFormat("CSS values conflict for parameter \"{0}\" ",parameter.Key);
                    }
                }
            }
        }