public bool Start(BoilerpipeHtmlContentHandler instance, string uri, string localName, string qName, IAttributes attributes) { string sizeAttr = attributes.GetValue("size"); if (sizeAttr != null) { Match m = FontSizeRegex.Match(sizeAttr); if (m.Success) { string rel = m.Groups[1].Value; int val = int.Parse(m.Groups[2].Value); int size; if (rel.Length == 0) { // absolute size = val; } else { // relative int prevSize; if (instance.FontSizeStack.Count == 0) { prevSize = 3; } else { prevSize = 3; foreach (var s in instance.FontSizeStack) { if (s != null) { prevSize = s.Value; break; } } } if (rel[0] == '+') { size = prevSize + val; } else { size = prevSize - val; } } instance.FontSizeStack.AddFirst(size); } else { instance.FontSizeStack.AddFirst((int?)null); } } else { instance.FontSizeStack.AddFirst((int?)null); } return(false); }
/// <summary> /// Generates the range block line. /// </summary> /// <param name="rLabel">The r label.</param> /// <param name="source">The source.</param> /// <param name="rect">The rect.</param> /// <param name="image">The image.</param> /// <param name="font">The font.</param> /// <param name="fontName">Name of the font.</param> /// <param name="isStrikethrough">if set to <c>true</c> [is strikethrough].</param> /// <param name="fontSize">Size of the font.</param> /// <param name="underlineType">Type of the underline.</param> /// <param name="isBold">if set to <c>true</c> [is bold].</param> /// <param name="isItalic">if set to <c>true</c> [is italic].</param> /// <param name="foreground">The foreground.</param> /// <returns></returns> static List <GcPrintableControl> GenerateRangeBlockLine(GcRichLabel rLabel, string source, Windows.Foundation.Rect rect, Image image, ref Font font, ref string fontName, ref bool isStrikethrough, ref double fontSize, ref UnderlineType underlineType, ref bool isBold, ref bool isItalic, ref Brush foreground) { List <GcPrintableControl> list = new List <GcPrintableControl>(); if ((!string.IsNullOrEmpty(source) && !rect.IsEmpty) && ((rect.Width != 0.0) && (rect.Height != 0.0))) { string str = string.Empty; while (!string.IsNullOrEmpty(source)) { string str2 = fontName; bool flag = isStrikethrough; double num = fontSize; UnderlineType single = underlineType; bool flag2 = isBold; bool flag3 = isItalic; Brush foregroundNext = foreground; int length = -1; length = source.IndexOf("&"); if (length < 0) { length = source.Length; } str = str + source.Substring(0, length); string str3 = ((length + 1) < source.Length) ? source.Substring(length + 1, 1) : string.Empty; int startIndex = -1; bool flag4 = false; PageInfoType pageNumber = PageInfoType.PageNumber; bool flag5 = false; int num4 = 0; try { Match match; switch (str3) { case "1": case "2": case "3": case "4": case "5": case "6": case "7": case "8": case "9": case "0": match = FontSizeRegex.Match(source.Substring(length)); if ((!match.Success || !match.Groups["fontSize"].Success) || string.IsNullOrEmpty(match.Groups["fontSize"].Value)) { goto Label_079D; } num = int.Parse(match.Groups["fontSize"].Value); flag4 = true; num4 = 0; startIndex = (length + "&".Length) + match.Groups["fontSize"].Value.Length; if (match.Groups["nextIsNumber"].Success) { startIndex++; } goto Label_07C0; case "K": { match = RgbColorRegex.Match(source.Substring(length)); if (!match.Success) { break; } byte r = byte.Parse(match.Groups["red"].Value, (NumberStyles)NumberStyles.AllowHexSpecifier); byte g = byte.Parse(match.Groups["green"].Value, (NumberStyles)NumberStyles.AllowHexSpecifier); byte b = byte.Parse(match.Groups["blue"].Value, (NumberStyles)NumberStyles.AllowHexSpecifier); foregroundNext = new SolidColorBrush(Windows.UI.Color.FromArgb(0xff, r, g, b)); flag4 = true; num4 = 0; startIndex = ((length + "&".Length) + "K".Length) + 6; goto Label_07C0; } case "S": flag = !flag; flag4 = true; num4 = 0; startIndex = (length + "&".Length) + "S".Length; goto Label_07C0; case "U": if (single != UnderlineType.None) { goto Label_04DA; } single = UnderlineType.Single; goto Label_04E2; case "\"": match = FontRegex.Match(source.Substring(length)); if (match.Success) { string str4 = match.Groups["fontName"].Value; string str5 = match.Groups["fontStyle"].Value; if (str4.IndexOf("-") < 0) { str2 = str4; flag4 = true; num4 = 0; } if (str5.IndexOf("-") < 0) { if (str5.IndexOf("Bold") >= 0) { flag2 = true; } if (str5.IndexOf("Italic") >= 0) { flag3 = true; } if (str5.IndexOf("Regular") >= 0) { flag2 = flag3 = false; } flag4 = true; num4 = 0; } startIndex = length + match.Value.Length; } goto Label_07C0; case "B": flag2 = !flag2; flag4 = true; num4 = 0; startIndex = (length + "&".Length) + "B".Length; goto Label_07C0; case "I": flag3 = !flag3; flag4 = true; num4 = 0; startIndex = (length + "&".Length) + "I".Length; goto Label_07C0; case "&": str = str + "&"; flag4 = true; num4 = 0; startIndex = length + ("&".Length * 2); goto Label_07C0; case "D": str = str + "{0}"; flag4 = true; num4 = 1; pageNumber = PageInfoType.Date; startIndex = (length + "&".Length) + "D".Length; goto Label_07C0; case "T": str = str + "{0}"; flag4 = true; num4 = 1; pageNumber = PageInfoType.Time; startIndex = (length + "&".Length) + "T".Length; goto Label_07C0; case "P": str = str + "{0}"; flag4 = true; num4 = 1; pageNumber = PageInfoType.PageNumber; startIndex = (length + "&".Length) + "P".Length; goto Label_07C0; case "N": str = str + "{0}"; flag4 = true; num4 = 1; pageNumber = PageInfoType.PageCount; startIndex = (length + "&".Length) + "N".Length; goto Label_07C0; case "G": if (image != null) { flag4 = true; num4 = 0; flag5 = true; } startIndex = (length + "&".Length) + "G".Length; goto Label_07C0; case "F": str = str + rLabel.WorkbookName; startIndex = (length + "&".Length) + "F".Length; goto Label_07C0; case "A": str = str + rLabel.WorksheetName; startIndex = (length + "&".Length) + "A".Length; goto Label_07C0; default: goto Label_079D; } if (!ThemeColorRegex.Match(source.Substring(length)).Success) { goto Label_079D; } foregroundNext = rLabel.Foreground; flag4 = true; num4 = 0; startIndex = ((length + "&".Length) + "K".Length) + 5; goto Label_07C0; Label_04DA: if (single == UnderlineType.Single) { single = UnderlineType.None; } Label_04E2: flag4 = true; num4 = 0; startIndex = (length + "&".Length) + "U".Length; goto Label_07C0; Label_079D: startIndex = length + "&".Length; } catch { startIndex = length + "&".Length; } Label_07C0: if (startIndex >= source.Length) { source = string.Empty; } else { source = source.Substring(startIndex); } if (!string.IsNullOrEmpty(str) && (flag4 || string.IsNullOrEmpty(source))) { GcLabel label = null; switch (num4) { case 0: label = new GcLabel(str); break; case 1: { GcPageInfo info = new GcPageInfo { Format = str, Type = pageNumber }; label = info; break; } } label.CanGrow = false; label.CanShrink = false; label.Foreground = foreground; if ((((font.FontFamilyName != fontName) || (font.Strikeout != isStrikethrough)) || ((font.FontSize != fontSize) || (font.Underline != underlineType))) || ((font.Bold != isBold) || (font.Italic != isItalic))) { font = new Font(fontName, fontSize); font.Strikeout = isStrikethrough; font.Bold = isBold; font.Italic = isItalic; font.Underline = underlineType; } label.Alignment.WordWrap = false; label.Font = font; list.Add(label); str = string.Empty; } if (flag5 && (image != null)) { GcImage image2 = new GcImage(image); list.Add(image2); flag5 = false; } fontName = str2; isStrikethrough = flag; fontSize = num; underlineType = single; isBold = flag2; isItalic = flag3; foreground = foregroundNext; } } return(list); }