public void InlineStyle_ParseTest() { string text = "color:red; /* c1 */ background-color: /* c2 */ ugly"; CssParser parser = new CssParser(); InlineStyle inlineStyle = parser.ParseInlineStyle(text, insertComments: true); Assert.IsNotNull(inlineStyle); Assert.AreEqual(0, inlineStyle.Start); Assert.AreEqual(text.Length, inlineStyle.Length); Assert.IsNull(inlineStyle.OpenCurlyBrace); Assert.IsNull(inlineStyle.CloseCurlyBrace); Assert.AreEqual(2, inlineStyle.Declarations.Count); Assert.AreEqual(0, inlineStyle.Declarations[0].Start); Assert.AreEqual(10, inlineStyle.Declarations[0].Length); Assert.AreEqual(20, inlineStyle.Declarations[1].Start); Assert.AreEqual(31, inlineStyle.Declarations[1].Length); Assert.AreEqual(3, inlineStyle.Children.Count); Assert.IsInstanceOfType(inlineStyle.Children[0], typeof(Declaration)); Assert.IsInstanceOfType(inlineStyle.Children[1], typeof(CComment)); Assert.IsInstanceOfType(inlineStyle.Children[2], typeof(Declaration)); }
public LineBreaking.IUnjustifiedLine<Printing.IPrintableLine> CreateLine(LineBreaking.ILineConstraint constraint, InlineStyle style, LineBreaking.IBreakPoint from, LineBreaking.IBreakPoint to, out InlineStyle newStyle) { IInterletter fromAsJapaneseInterletterspace; IInterletter toAsJapaneseInterletterspace; StartOfParagraph fromAsStart; EndOfParagraph toAsEnd; fromAsJapaneseInterletterspace = from as IInterletter; toAsJapaneseInterletterspace = to as IInterletter; if (fromAsJapaneseInterletterspace != null) { if (toAsJapaneseInterletterspace != null) { return CreateLine(constraint, fromAsJapaneseInterletterspace, toAsJapaneseInterletterspace, style, out newStyle); } else { toAsEnd = to as EndOfParagraph; if (toAsEnd != null) { return CreateLine(constraint, fromAsJapaneseInterletterspace, toAsEnd, style, out newStyle); } else { throw new ArgumentException("type error", "to"); } } } else { fromAsStart = from as StartOfParagraph; if (fromAsStart != null) { if (toAsJapaneseInterletterspace != null) { return CreateLine(constraint, fromAsStart, toAsJapaneseInterletterspace, style, out newStyle); } else { toAsEnd = to as EndOfParagraph; if (toAsEnd != null) { return CreateLine(constraint, fromAsStart, toAsEnd, style, out newStyle); } else { throw new ArgumentException("type error", "to"); } } } else { throw new ArgumentException("type error", "start"); } } }
public LineBreaking.IUnjustifiedLine CreateLine(InlineStyle style, LineBreaking.IBreakPoint from, LineBreaking.IBreakPoint to, out InlineStyle newStyle) { JapaneseInterletterspace fromAsJapaneseInterletterspace; JapaneseInterletterspace toAsJapaneseInterletterspace; StartOfParagraph fromAsStart; EndOfParagraph toAsEnd; fromAsJapaneseInterletterspace = from as JapaneseInterletterspace; toAsJapaneseInterletterspace = to as JapaneseInterletterspace; if (fromAsJapaneseInterletterspace != null) { if (toAsJapaneseInterletterspace != null) { return(CreateLine(fromAsJapaneseInterletterspace, toAsJapaneseInterletterspace, style, out newStyle)); } else { toAsEnd = to as EndOfParagraph; if (toAsEnd != null) { return(CreateLine(fromAsJapaneseInterletterspace, toAsEnd, style, out newStyle)); } else { throw new ArgumentException("type error", "to"); } } } else { fromAsStart = from as StartOfParagraph; if (fromAsStart != null) { if (toAsJapaneseInterletterspace != null) { return(CreateLine(fromAsStart, toAsJapaneseInterletterspace, style, out newStyle)); } else { toAsEnd = to as EndOfParagraph; if (toAsEnd != null) { return(CreateLine(fromAsStart, toAsEnd, style, out newStyle)); } else { throw new ArgumentException("type error", "to"); } } } else { throw new ArgumentException("type error", "start"); } } }
public static UnjustifiedLine Solve( LineBreaking.ILineConstraint constraint, GlueProperty startGlue, IEnumerable <IFormatObject> objectList, GlueProperty endGlue, float penaltyValue, Heading heading, InlineStyle style, out InlineStyle newStyle) { IFragment[] fragments = ConvertToFragments(ref startGlue, objectList, ref endGlue, style, out newStyle); var rubyLayoutedBuffer = LayoutRubyInLine(constraint, fragments, endGlue.Length); return(new UnjustifiedLine(rubyLayoutedBuffer, penaltyValue, heading)); }
private static InlineLayoutEngine.AtomicFragment[] GenerateFragments(InlineStyle style, IFormatObject[] objects, GlueProperty startGlue) { Context baseContext = new Context(style, objects.Length); baseContext.PutGlue(startGlue); foreach (var x in objects) { baseContext.Put(x); } try { return(baseContext._buffer.ConvertAll(x => (InlineLayoutEngine.AtomicFragment)x).ToArray()); } catch (Exception ex) { throw new NotImplementedException("texts both with formatting and with ruby is not supported", ex); } }
internal InlineStyle ParseInlineStyle(ITextProvider text, bool insertComments) { InlineStyle inlineStyle = new InlineStyle(); ICssTokenizer tokenizer = CreateTokenizer(); ITextProvider textProvider = text ?? new StringTextProvider(string.Empty); TokenList tokens = tokenizer.Tokenize(textProvider, 0, textProvider.Length, keepWhiteSpace: false); IList <Comment> comments = ExtractComments(text, tokens, 0, tokens.Count); TokenStream tokenStream = new TokenStream(tokens) { SkipComments = true }; ItemFactory itemFactory = new ItemFactory(ExternalItemFactory, textProvider, tokenStream); if (!inlineStyle.Parse(itemFactory, textProvider, tokenStream)) { inlineStyle = null; } else { if (insertComments) { foreach (ParseItem comment in comments) { inlineStyle.InsertChildIntoSubtree(comment); } } // There must be a StyleSheet root object, so create one StyleSheet styleSheet = new StyleSheet { TextProvider = textProvider }; styleSheet.Children.Add(inlineStyle); } return(inlineStyle); }
public UnjustifiedLine Build( GlueProperty startGlue, IEnumerable <IFormatObject> objectList, GlueProperty endGlue, float penaltyValue, InlineStyle style, out InlineStyle newStyle) { var styleClone = style.Clone(); Context context = new Context(styleClone, 64); context.PutGlue(startGlue); foreach (var obj in objectList) { context.Put(obj); } context.PutGlue(endGlue); var buffer = context.Buffer.ToArray(); //TODO: この処理が同じオブジェクト列に対して繰り返し呼ばれる。もっと前段階に運搬 var rubyLayoutedBuffer = UnjustifiedLine.LayoutRubyInLine(buffer, endGlue.Length); newStyle = styleClone; return(new UnjustifiedLine(rubyLayoutedBuffer, context.AccumulatedGlue, penaltyValue)); }
private static IFragment[] ConvertToFragments(ref GlueProperty startGlue, IEnumerable <IFormatObject> objectList, ref GlueProperty endGlue, InlineStyle style, out InlineStyle newStyle) { var styleClone = style.Clone(); var context = new Context(styleClone, 64); context.PutGlue(startGlue); foreach (var obj in objectList) { context.Put(obj); } context.PutGlue(endGlue); newStyle = styleClone; return(context.Fragments); }
private LineBreaking.IUnjustifiedLine <Printing.IPrintableLine> CreateLine(LineBreaking.ILineConstraint constraint, IInterletter from, IInterletter to, InlineStyle style, out InlineStyle newStyle) { var fromIndex = Array.IndexOf(_objectList, from); if (fromIndex == -1) { throw new ArgumentException("from"); } var toIndex = Array.IndexOf(_objectList, to); if (toIndex == -1) { throw new ArgumentException("to"); } return(InlineLayoutEngine.Solve( constraint, new GlueProperty(from.IndentAfterBreak, 0, 0), _objectList.Skip(fromIndex + 1).Take(toIndex - fromIndex - 1), to.GlueBeforeBreak, PenaltyValue(to), _heading, style, out newStyle)); }
private LineBreaking.IUnjustifiedLine<Printing.IPrintableLine> CreateLine(LineBreaking.ILineConstraint constraint, StartOfParagraph from, IInterletter to, InlineStyle style, out InlineStyle newStyle) { var toIndex = Array.IndexOf(_objectList, to); if (toIndex == -1) throw new ArgumentException("to"); return InlineLayoutEngine.Solve(constraint, from.Glue, _objectList.Take(toIndex), to.GlueBeforeBreak, PenaltyValue(to), _heading, style, out newStyle); }
public ShowHideWebParser(InlineStyle style) : base() { this._inlineStyle = style; }
private LineBreaking.IUnjustifiedLine CreateLine(JapaneseInterletterspace from, EndOfParagraph to, InlineStyle style, out InlineStyle newStyle) { var fromIndex = Array.IndexOf(_objectList, from); if (fromIndex == -1) { throw new ArgumentException("from"); } return(_lineBuilder.Build( new GlueProperty(from.IndentAfterBreak, 0, 0), _objectList.Skip(fromIndex + 1), to.Glue, PenaltyValue(to), style, out newStyle)); }
private LineBreaking.IUnjustifiedLine CreateLine(StartOfParagraph from, JapaneseInterletterspace to, InlineStyle style, out InlineStyle newStyle) { var toIndex = Array.IndexOf(_objectList, to); if (toIndex == -1) { throw new ArgumentException("to"); } return(_lineBuilder.Build(from.Glue, _objectList.Take(toIndex), to.GlueBeforeBreak, PenaltyValue(to), style, out newStyle)); }
private LineBreaking.IUnjustifiedLine CreateLine(StartOfParagraph from, EndOfParagraph to, InlineStyle style, out InlineStyle newStyle) { return(_lineBuilder.Build(from.Glue, _objectList, to.Glue, PenaltyValue(to), style, out newStyle)); }
public Context(InlineStyle style, int capacity) { _buffer = new List <InlineLayoutEngine.IFragment>(capacity); _accumulatedGlue = default(GlueProperty); _currentStyle = style; }
private LineBreaking.IUnjustifiedLine<Printing.IPrintableLine> CreateLine(LineBreaking.ILineConstraint constraint, IInterletter from, EndOfParagraph to, InlineStyle style, out InlineStyle newStyle) { var fromIndex = Array.IndexOf(_objectList, from); if (fromIndex == -1) throw new ArgumentException("from"); return InlineLayoutEngine.Solve( constraint, new GlueProperty(from.IndentAfterBreak, 0, 0), _objectList.Skip(fromIndex + 1), to.Glue, PenaltyValue(to), _heading, style, out newStyle); }
public LineBreaking.IUnjustifiedLine <Printing.IPrintableLine> CreateLine(LineBreaking.ILineConstraint constraint, InlineStyle style, LineBreaking.IBreakPoint from, LineBreaking.IBreakPoint to, out InlineStyle newStyle) { IInterletter fromAsJapaneseInterletterspace; IInterletter toAsJapaneseInterletterspace; StartOfParagraph fromAsStart; EndOfParagraph toAsEnd; fromAsJapaneseInterletterspace = from as IInterletter; toAsJapaneseInterletterspace = to as IInterletter; if (fromAsJapaneseInterletterspace != null) { if (toAsJapaneseInterletterspace != null) { return(CreateLine(constraint, fromAsJapaneseInterletterspace, toAsJapaneseInterletterspace, style, out newStyle)); } else { toAsEnd = to as EndOfParagraph; if (toAsEnd != null) { return(CreateLine(constraint, fromAsJapaneseInterletterspace, toAsEnd, style, out newStyle)); } else { throw new ArgumentException("type error", "to"); } } } else { fromAsStart = from as StartOfParagraph; if (fromAsStart != null) { if (toAsJapaneseInterletterspace != null) { return(CreateLine(constraint, fromAsStart, toAsJapaneseInterletterspace, style, out newStyle)); } else { toAsEnd = to as EndOfParagraph; if (toAsEnd != null) { return(CreateLine(constraint, fromAsStart, toAsEnd, style, out newStyle)); } else { throw new ArgumentException("type error", "to"); } } } else { throw new ArgumentException("type error", "start"); } } }
private LineBreaking.IUnjustifiedLine<Printing.IPrintableLine> CreateLine(LineBreaking.ILineConstraint constraint, StartOfParagraph from, EndOfParagraph to, InlineStyle style, out InlineStyle newStyle) { return InlineLayoutEngine.Solve(constraint, from.Glue, _objectList, to.Glue, PenaltyValue(to), _heading, style, out newStyle); }
private LineBreaking.IUnjustifiedLine <Printing.IPrintableLine> CreateLine(LineBreaking.ILineConstraint constraint, StartOfParagraph from, EndOfParagraph to, InlineStyle style, out InlineStyle newStyle) { return(InlineLayoutEngine.Solve(constraint, from.Glue, _objectList, to.Glue, PenaltyValue(to), _heading, style, out newStyle)); }
private LineBreaking.IUnjustifiedLine <Printing.IPrintableLine> CreateLine(LineBreaking.ILineConstraint constraint, StartOfParagraph from, IInterletter to, InlineStyle style, out InlineStyle newStyle) { var toIndex = Array.IndexOf(_objectList, to); if (toIndex == -1) { throw new ArgumentException("to"); } return(InlineLayoutEngine.Solve(constraint, from.Glue, _objectList.Take(toIndex), to.GlueBeforeBreak, PenaltyValue(to), _heading, style, out newStyle)); }
private static UnjustifiedLine.JapaneseLetterFragment[] GenerateFragments(InlineStyle style, IFormatObject[] objects, GlueProperty startGlue) { Context baseContext = new Context(style, objects.Length); baseContext.PutGlue(startGlue); foreach (var x in objects) { baseContext.Put(x); } try { return(Array.ConvertAll(baseContext.Buffer, x => (UnjustifiedLine.JapaneseLetterFragment)x)); } catch (Exception ex) { throw new NotImplementedException("texts both with formatting and with ruby is not supported", ex); } }