internal WriterState(HtmlMobileTextWriter writer) : base(writer) { _writer = writer; _stack = new Stack(); _current = new WriterStyle(); _tagsWritten = new Stack(); }
public override void EnterFormat(Style style) { WriterStyle writerStyle = new WriterStyle(style); writerStyle.Layout = false; EnterStyle(writerStyle); }
private bool FontChange(WriterStyle newStyle) { return( ((_current.FontColor != newStyle.FontColor) && (_writer.RenderFontColor)) || ((_current.FontSize != newStyle.FontSize) && (_writer.RenderFontSize)) || ((_current.FontName != newStyle.FontName) && (_writer.RenderFontName)) ); }
private bool DivChange(WriterStyle newStyle) { return( (newStyle.Layout) && (((newStyle.Wrapping != _current.Wrapping) && (_writer.RenderDivNoWrap)) || ((newStyle.Alignment != _current.Alignment) && (_writer.RenderDivAlign))) ); }
public static void WithAppend(StringBuilder sb, Global global, WriterStyle style, Action <CSTWriter> f) { var sw = new StringWriter(sb); var w = new CSTWriter(global, style, sw); f(w); sw.Flush(); }
/* * Pushes the current WriterStyle and tagsWritten stack for later use, * starts using a new default WriterStyle */ internal void PushState() { _writer.ShouldEnsureStyle = true; _stack.Push(_current); _current = new WriterStyle(); _stack.Push(_tagsWritten); _tagsWritten = new Stack(); _stack.Push(BreakPending); BreakPending = false; }
/* * Pops the last WriterStyle pushed and makes it current * and restores the tagsWritten stack */ internal WriterStyle PopState() { _writer.ShouldEnsureStyle = true; BreakPending = (bool)_stack.Pop(); //close all open tags while (_tagsWritten.Count > 0) { CloseTag(); } _tagsWritten = (Stack)_stack.Pop(); _current = (WriterStyle)_stack.Pop(); return(_current); }
public override void EnterLayout(Style style) { if (MaintainState) { base.EnterLayout(style); return; } //we are not maintaining state, so begin a new context BeginStyleContext(); //create a WriterStyle and turn off formatting output WriterStyle newStyle = new WriterStyle(style); newStyle.Format = false; //transition to the new style, capturing output _currentState.Transition(newStyle); //Clear stack so we do not interfere with Write*() _currentState.Transition(_defaultWriterStyle, false); //restore the context EndStyleContext(); }
public override void ExitLayout(Style style, bool breakAfter) { if (MaintainState) { base.ExitLayout(style, breakAfter); return; } //we are not maintaining state, so begin a new context BeginStyleContext(); //create a WriterStyle and turn off formatting output WriterStyle newStyle = new WriterStyle(style); newStyle.Format = false; //Setup stack like it would be after base.EnterLayout() _currentState.Transition(newStyle, false); //transition to default state and capture output _currentState.Transition(_defaultWriterStyle); //close the context, to flush all pending tags EndStyleContext(); }
/* Pops the last WriterStyle pushed and makes it current and restores the tagsWritten stack */ internal WriterStyle PopState() { _writer.ShouldEnsureStyle = true; BreakPending = (bool)_stack.Pop(); //close all open tags while(_tagsWritten.Count > 0) { CloseTag(); } _tagsWritten = (Stack)_stack.Pop(); _current = (WriterStyle)_stack.Pop(); return _current; }
public CSTWriter(Global global, WriterStyle style, TextWriter tw) : base(tw, true) { Global = global; Style = style; }
private bool FontChange(WriterStyle newStyle) { return ( (( _current.FontColor != newStyle.FontColor ) && (_writer.RenderFontColor)) || (( _current.FontSize != newStyle.FontSize ) && (_writer.RenderFontSize)) || (( _current.FontName != newStyle.FontName ) && (_writer.RenderFontName)) ); }
internal void Push(WriterStyle style) { _stack.Push(style); _writer.ShouldEnsureStyle = true; }
/* all calls to Enter... converge to this */ private void EnterStyle(WriterStyle style) { _currentState.Push(style); }
/* all calls to Enter... converge to this */ private void EnterStyle(WriterStyle style) { _currentState.Push(style); }
internal void Transition(WriterStyle newStyle) { Transition(newStyle, true); }
private bool DivChange(WriterStyle newStyle) { return ( (newStyle.Layout) && (((newStyle.Wrapping != _current.Wrapping) && (_writer.RenderDivNoWrap)) || ((newStyle.Alignment != _current.Alignment) && (_writer.RenderDivAlign)) ) ); }
internal void Transition(WriterStyle newStyle) { Transition(newStyle, true); }
internal void Transition(WriterStyle newStyle, bool captureOutput) { HtmlMobileTextWriter tempWriter = _writer; try { if(!captureOutput) { tempWriter = _writer; _writer = new HtmlMobileTextWriter( new HtmlTextWriter(new StringWriter(CultureInfo.InvariantCulture)), tempWriter.Device); } if(_inTransition) { return; } else { _inTransition = true; } if(Count == 0) { while(_tagsWritten.Count > 0) { CloseTag(); } _inTransition= false; return; } //close italic if target format !italic if(( _current.Italic && !newStyle.Italic ) && (_writer.RenderItalic)) { while(_current.Italic) { CloseTag(); } } //close bold if target format !bold if(( _current.Bold && !newStyle.Bold ) && (_writer.RenderBold)) { while(_current.Bold) { CloseTag(); } } //if the target FontColor is Color.Empty, then we need to //close all open color tags if( (newStyle.FontColor == Color.Empty) && (_current.FontColor != Color.Empty) && (_writer.RenderFontColor) ) { while(_current.FontColor != Color.Empty) { CloseTag(); } } //if the target FontName is String.Empty, then we need to //close all open name tags if( (newStyle.FontName != null && newStyle.FontName.Length == 0) && (_current.FontName == null || _current.FontName.Length > 0) && (_writer.RenderFontName) ) { while(_current.FontName == null || _current.FontName.Length > 0) { CloseTag(); } } //close the font if it is of the same or a later generation //and differs bool newFont = FontChange(newStyle); if(newFont) { while( FontLevel >= Count ) { CloseTag(); } } //if the new wrapping is Wrap, and the current is NoWrap //the outer NoWrap must be removed if( (newStyle.Wrapping == Wrapping.Wrap) && (_current.Wrapping == Wrapping.NoWrap) && (_writer.RenderDivNoWrap) ) { while(_current.Wrapping != Wrapping.Wrap) { CloseTag(); } } //if the alignment differs for the same generation, close any divs at this level if(( newStyle.Alignment != _current.Alignment ) && ( _writer.RenderDivAlign)) { while( DivLevel >= Count ) { CloseTag(); } } //determine if we will be opening a div before writing any break bool newDiv = DivChange(newStyle); //an opening div will function as a logical break if((BreakPending) && (!(newDiv))) { ((HtmlMobileTextWriter)_writer).WriteBreak(); BreakPending = false; } if(newDiv) { while(_current.Bold || _current.Italic || (FontLevel == Count)) { CloseTag(); } } newFont = FontChange(newStyle); newDiv = DivChange(newStyle); //open div if(newDiv && newStyle.Layout) { DivStyleTag div = new DivStyleTag(Count); BreakPending = false; if( ((_writer.BeforeFirstControlWritten) || (_writer.InputWritten)) && (_writer.Device.Type == _pocketPC) && (_writer.Device.MinorVersion == 0) && (_writer.Device.MajorVersion == 4) && (newStyle.Alignment != _current.Alignment) ) { _writer.WriteBreak(); _writer.InputWritten = false; } _writer.WriteBeginTag("div"); DivLevel = Count; if(newStyle.Wrapping == Wrapping.NoWrap) { if(_writer.RenderDivNoWrap) { _writer.Write(" nowrap"); } div.Wrapping = Wrapping.NoWrap; _current.Wrapping = Wrapping.NoWrap; } else { div.Wrapping = Wrapping.Wrap; _current.Wrapping = Wrapping.Wrap; } if(newStyle.Alignment != _current.Alignment) { if(_writer.RenderDivAlign) { _writer.WriteAttribute( "align", Enum.GetName(typeof(Alignment), newStyle.Alignment)); } _current.Alignment = newStyle.Alignment; div.Alignment = newStyle.Alignment; div.AlignmentWritten = true; } _tagsWritten.Push(div); _writer.Write(">"); } //open font if(newFont && newStyle.Format) { FontStyleTag fontTag = new FontStyleTag(Count); _writer.WriteBeginTag("font"); if(_current.FontSize != newStyle.FontSize) { String relativeSize; if(newStyle.FontSize == FontSize.Large) { relativeSize = ( ((HtmlMobileTextWriter)_writer).Device.Type == _pocketPC) ? "+2" : "+1"; _current.FontSize = FontSize.Large; fontTag.FontSize = FontSize.Large; } else if(newStyle.FontSize == FontSize.Small) { relativeSize = "-1"; _current.FontSize = FontSize.Small; fontTag.FontSize = FontSize.Small; } else //(newStyle.FontSize == FontSize.Normal) { relativeSize = "+0"; _current.FontSize = FontSize.Normal; fontTag.FontSize = FontSize.Normal; } if(_writer.RenderFontSize) { _writer.WriteAttribute("size", relativeSize); } } if(_current.FontColor != newStyle.FontColor) { if(_writer.RenderFontColor) { _writer.WriteAttribute( "color", ColorTranslator.ToHtml(newStyle.FontColor)); } _current.FontColor = newStyle.FontColor; fontTag.Color = newStyle.FontColor; } if(_current.FontName != newStyle.FontName) { if(_writer.RenderFontName) { _writer.WriteAttribute("face", newStyle.FontName); } _current.FontName = newStyle.FontName; fontTag.Name = newStyle.FontName; } _writer.Write(">"); _tagsWritten.Push(fontTag); FontLevel = Count; } //open bold if(newStyle.Format) { if( newStyle.Bold && !_current.Bold && _writer.RenderBold ) { _writer.WriteFullBeginTag("b"); _current.Bold = true; _tagsWritten.Push(new BoldStyleTag(Count)); } //open italic if( newStyle.Italic && !_current.Italic && _writer.RenderItalic ) { _writer.WriteFullBeginTag("i"); _current.Italic = true; _tagsWritten.Push(new ItalicStyleTag(Count)); } } _inTransition = false; } finally { _writer = tempWriter; } }
/* Pushes the current WriterStyle and tagsWritten stack for later use, starts using a new default WriterStyle */ internal void PushState() { _writer.ShouldEnsureStyle = true; _stack.Push(_current); _current = new WriterStyle(); _stack.Push(_tagsWritten); _tagsWritten = new Stack(); _stack.Push(BreakPending); BreakPending = false; }
internal WriterState(HtmlMobileTextWriter writer) : base(writer) { _writer = writer; _stack = new Stack(); _current = new WriterStyle(); _tagsWritten = new Stack(); }
internal void Push(WriterStyle style) { _stack.Push(style); _writer.ShouldEnsureStyle = true; }
internal void Transition(WriterStyle newStyle, bool captureOutput) { HtmlMobileTextWriter tempWriter = _writer; try { if (!captureOutput) { tempWriter = _writer; _writer = new HtmlMobileTextWriter( new HtmlTextWriter(new StringWriter(CultureInfo.InvariantCulture)), tempWriter.Device); } if (_inTransition) { return; } else { _inTransition = true; } if (Count == 0) { while (_tagsWritten.Count > 0) { CloseTag(); } _inTransition = false; return; } //close italic if target format !italic if ((_current.Italic && !newStyle.Italic) && (_writer.RenderItalic)) { while (_current.Italic) { CloseTag(); } } //close bold if target format !bold if ((_current.Bold && !newStyle.Bold) && (_writer.RenderBold)) { while (_current.Bold) { CloseTag(); } } //if the target FontColor is Color.Empty, then we need to //close all open color tags if ( (newStyle.FontColor == Color.Empty) && (_current.FontColor != Color.Empty) && (_writer.RenderFontColor)) { while (_current.FontColor != Color.Empty) { CloseTag(); } } //if the target FontName is String.Empty, then we need to //close all open name tags if ( (newStyle.FontName != null && newStyle.FontName.Length == 0) && (_current.FontName == null || _current.FontName.Length > 0) && (_writer.RenderFontName)) { while (_current.FontName == null || _current.FontName.Length > 0) { CloseTag(); } } //close the font if it is of the same or a later generation //and differs bool newFont = FontChange(newStyle); if (newFont) { while (FontLevel >= Count) { CloseTag(); } } //if the new wrapping is Wrap, and the current is NoWrap //the outer NoWrap must be removed if ( (newStyle.Wrapping == Wrapping.Wrap) && (_current.Wrapping == Wrapping.NoWrap) && (_writer.RenderDivNoWrap)) { while (_current.Wrapping != Wrapping.Wrap) { CloseTag(); } } //if the alignment differs for the same generation, close any divs at this level if ((newStyle.Alignment != _current.Alignment) && (_writer.RenderDivAlign)) { while (DivLevel >= Count) { CloseTag(); } } //determine if we will be opening a div before writing any break bool newDiv = DivChange(newStyle); //an opening div will function as a logical break if ((BreakPending) && (!(newDiv))) { ((HtmlMobileTextWriter)_writer).WriteBreak(); BreakPending = false; } if (newDiv) { while (_current.Bold || _current.Italic || (FontLevel == Count)) { CloseTag(); } } newFont = FontChange(newStyle); newDiv = DivChange(newStyle); //open div if (newDiv && newStyle.Layout) { DivStyleTag div = new DivStyleTag(Count); BreakPending = false; if ( ((_writer.BeforeFirstControlWritten) || (_writer.InputWritten)) && (_writer.Device.Type == _pocketPC) && (_writer.Device.MinorVersion == 0) && (_writer.Device.MajorVersion == 4) && (newStyle.Alignment != _current.Alignment)) { _writer.WriteBreak(); _writer.InputWritten = false; } _writer.WriteBeginTag("div"); DivLevel = Count; if (newStyle.Wrapping == Wrapping.NoWrap) { if (_writer.RenderDivNoWrap) { _writer.Write(" nowrap"); } div.Wrapping = Wrapping.NoWrap; _current.Wrapping = Wrapping.NoWrap; } else { div.Wrapping = Wrapping.Wrap; _current.Wrapping = Wrapping.Wrap; } if (newStyle.Alignment != _current.Alignment) { if (_writer.RenderDivAlign) { _writer.WriteAttribute( "align", Enum.GetName(typeof(Alignment), newStyle.Alignment)); } _current.Alignment = newStyle.Alignment; div.Alignment = newStyle.Alignment; div.AlignmentWritten = true; } _tagsWritten.Push(div); _writer.Write(">"); } //open font if (newFont && newStyle.Format) { FontStyleTag fontTag = new FontStyleTag(Count); _writer.WriteBeginTag("font"); if (_current.FontSize != newStyle.FontSize) { String relativeSize; if (newStyle.FontSize == FontSize.Large) { relativeSize = ( ((HtmlMobileTextWriter)_writer).Device.Type == _pocketPC) ? "+2" : "+1"; _current.FontSize = FontSize.Large; fontTag.FontSize = FontSize.Large; } else if (newStyle.FontSize == FontSize.Small) { relativeSize = "-1"; _current.FontSize = FontSize.Small; fontTag.FontSize = FontSize.Small; } else //(newStyle.FontSize == FontSize.Normal) { relativeSize = "+0"; _current.FontSize = FontSize.Normal; fontTag.FontSize = FontSize.Normal; } if (_writer.RenderFontSize) { _writer.WriteAttribute("size", relativeSize); } } if (_current.FontColor != newStyle.FontColor) { if (_writer.RenderFontColor) { _writer.WriteAttribute( "color", ColorTranslator.ToHtml(newStyle.FontColor)); } _current.FontColor = newStyle.FontColor; fontTag.Color = newStyle.FontColor; } if (_current.FontName != newStyle.FontName) { if (_writer.RenderFontName) { _writer.WriteAttribute("face", newStyle.FontName); } _current.FontName = newStyle.FontName; fontTag.Name = newStyle.FontName; } _writer.Write(">"); _tagsWritten.Push(fontTag); FontLevel = Count; } //open bold if (newStyle.Format) { if (newStyle.Bold && !_current.Bold && _writer.RenderBold) { _writer.WriteFullBeginTag("b"); _current.Bold = true; _tagsWritten.Push(new BoldStyleTag(Count)); } //open italic if (newStyle.Italic && !_current.Italic && _writer.RenderItalic) { _writer.WriteFullBeginTag("i"); _current.Italic = true; _tagsWritten.Push(new ItalicStyleTag(Count)); } } _inTransition = false; } finally { _writer = tempWriter; } }
internal DesignerTextWriter(bool maintainState) : base(new StringWriter(CultureInfo.CurrentCulture), DesignerCapabilities.Instance) { MaintainState = maintainState; _defaultWriterStyle = new WriterStyle(); }
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.EnterFormat"]/*' /> public override void EnterFormat(Style style) { WriterStyle writerStyle = new WriterStyle(style); writerStyle.Layout = false; EnterStyle(writerStyle); }