static int EvaluateFontAndTextColor(DrawBoard canvas, TextSpanStyle spanStyle) { var font = spanStyle.ReqFont; var color = spanStyle.FontColor; var currentTextFont = canvas.CurrentFont; var currentTextColor = canvas.CurrentTextColor; if (font != null && font != currentTextFont) { if (currentTextColor != color) { return(DIFF_FONT_DIFF_TEXT_COLOR); } else { return(DIFF_FONT_SAME_TEXT_COLOR); } } else { if (currentTextColor != color) { return(SAME_FONT_DIFF_TEXT_COLOR); } else { return(SAME_FONT_SAME_TEXT_COLOR); } } }
// protected override void OnStart(AppHost host) { _textbox = new LayoutFarm.CustomWidgets.TextBox(400, 300, true); _textbox.SetLocation(20, 20); var style1 = new TextEditing.TextSpanStyle(); style1.ReqFont = new PixelFarm.Drawing.RequestFont("tahoma", 14); style1.FontColor = new PixelFarm.Drawing.Color(0, 0, 0); _textbox.DefaultSpanStyle = style1; var textSplitter = new CustomWidgets.ContentTextSplitter(); _textbox.TextSplitter = textSplitter; _sgBox = new SuggestionWindowMx(300, 200); _sgBox.UserConfirmSelectedItem += new EventHandler(sgBox_UserConfirmSelectedItem); _sgBox.ListItemKeyboardEvent += new EventHandler <UIKeyEventArgs>(sgBox_ListItemKeyboardEvent); _sgBox.Hide(); //------------------------------------ //create special text surface listener var textSurfaceListener = new LayoutFarm.TextEditing.TextSurfaceEventListener(); textSurfaceListener.CharacterAdded += (s, e) => UpdateSuggestionList(); textSurfaceListener.CharacterRemoved += (s, e) => UpdateSuggestionList(); textSurfaceListener.PreviewArrowKeyDown += new EventHandler <TextEditing.TextDomEventArgs>(textSurfaceListener_PreviewArrowKeyDown); textSurfaceListener.PreviewEnterKeyDown += new EventHandler <TextEditing.TextDomEventArgs>(textSurfaceListener_PreviewEnterKeyDown); _textbox.TextEventListener = textSurfaceListener; //------------------------------------ host.AddChild(_textbox); host.AddChild(_sgBox.GetPrimaryUI()); //------------------------------------ BuildSampleCountryList(); }
public DocActionFormatting(TextSpanStyle textStyle, int startLineNumber, int startCharIndex, int endLineNumber, int endCharIndex) : base(startLineNumber, startCharIndex) { _textStyle = textStyle; _endLineNumber = endLineNumber; _endCharIndex = endCharIndex; }
// protected override void OnStart(AppHost host) { _textbox = new LayoutFarm.CustomWidgets.TextBox(400, 30, false); _textbox.SetLocation(20, 20); var style2 = new TextEditing.TextSpanStyle(); style2.ReqFont = new PixelFarm.Drawing.RequestFont("tahoma", 14); style2.FontColor = new PixelFarm.Drawing.Color(0, 0, 0); _textbox.DefaultSpanStyle = style2; var textSplitter = new LayoutFarm.CustomWidgets.ContentTextSplitter(); _textbox.TextSplitter = textSplitter; _listbox = new CustomWidgets.ListBox(300, 200); _listbox.SetLocation(0, 40); _listbox.Visible = false; //------------------------------------ //create special text surface listener var textSurfaceListener = new LayoutFarm.TextEditing.TextSurfaceEventListener(); textSurfaceListener.CharacterAdded += (s, e) => UpdateSuggestionList(); textSurfaceListener.CharacterRemoved += (s, e) => UpdateSuggestionList(); textSurfaceListener.PreviewArrowKeyDown += new EventHandler <TextEditing.TextDomEventArgs>(textSurfaceListener_PreviewArrowKeyDown); textSurfaceListener.PreviewEnterKeyDown += new EventHandler <TextEditing.TextDomEventArgs>(textSurfaceListener_PreviewEnterKeyDown); _textbox.TextEventListener = textSurfaceListener; //------------------------------------ host.AddChild(_textbox); host.AddChild(_listbox); //------------------------------------ BuildSampleCountryList(); }
public void AddUnformattedStringToCurrentLine(RootGraphic root, string str, TextSpanStyle initTextSpanStyle) { //this should be a text-service work *** //TODO: use specific text model to format this document using (System.IO.StringReader reader = new System.IO.StringReader(str)) { string line = reader.ReadLine(); List <EditableTextRun> runs = new List <EditableTextRun>(); int lineCount = 0; while (line != null) { if (lineCount > 0) { runs.Add(new EditableTextRun(root, '\n', initTextSpanStyle)); } if (line.Length > 0) { runs.Add(new EditableTextRun(root, line, initTextSpanStyle)); } // line = reader.ReadLine(); lineCount++; } AddTextRunsToCurrentLine(runs.ToArray()); } }
protected override void OnStart(AppHost host) { { var reqFont1 = new PixelFarm.Drawing.RequestFont("Sarabun", 14); var textbox1 = new LayoutFarm.CustomWidgets.TextBox(400, 100, true); var style1 = new TextEditing.TextSpanStyle(); style1.ReqFont = reqFont1; //test with various font style style1.FontColor = new PixelFarm.Drawing.Color(0, 0, 0); textbox1.DefaultSpanStyle = style1; host.AddChild(textbox1); } //------------------- //{ // var reqFont2 = new PixelFarm.Drawing.RequestFont("Sarabun", 10); // //this version we need to set a style font each textbox // var textbox2 = new LayoutFarm.CustomWidgets.TextBox(400, 500, true); // var style2 = new TextEditing.TextSpanStyle(); // style2.ReqFont = reqFont2; // style2.FontColor = new PixelFarm.Drawing.Color(0, 0, 0); // textbox2.DefaultSpanStyle = style2; // textbox2.SetLocation(20, 120); // host.AddChild(textbox2); // var textSplitter = new ContentTextSplitter(); // textbox2.TextSplitter = textSplitter; // textbox2.Text = "Hello World!"; //} }
internal SolidTextRun(RootGraphic gfx, char[] copyBuffer, TextSpanStyle style) : base(gfx) { //check line break? _spanStyle = style; _mybuffer = copyBuffer; UpdateRunWidth(); }
// public override void SetStyle(TextSpanStyle spanStyle) { //TODO: review this again //update style may affect the 'visual' layout of the span //the span may expand large or shrink down //so we invalidate graphics area pre and post this.InvalidateGraphics(); _spanStyle = spanStyle; this.InvalidateGraphics(); UpdateRunWidth(); }
public EditableTextRun(RootGraphic gfx, char c, TextSpanStyle style) : base(gfx) { _spanStyle = style; SetNewContent(new char[] { c }); if (c == '\n') { //TODO: review line break span this.IsLineBreak = true; } //check line break? UpdateRunWidth(); }
public EditableTextRun(RootGraphic gfx, char[] copyBuffer, TextSpanStyle style) : base(gfx) { //we need font info (in style) for evaluating the size fo this span //without font info we can't measure the size of this span _spanStyle = style; SetNewContent(copyBuffer); UpdateRunWidth(); #if DEBUG this.dbugBreak = true; #endif }
public TextEditRenderBox( RootGraphic rootgfx, int width, int height, bool isMultiLine, bool isEditable = true) : base(rootgfx, width, height) { _isEditable = isEditable; if (isEditable) { GlobalCaretController.RegisterCaretBlink(rootgfx); // _myCaret = new CaretRenderElement(rootgfx, 2, 17); _myCaret.TransparentForAllEvents = true; } RenderBackground = RenderCaret = RenderSelectionRange = RenderMarkers = true; // MayHasViewport = true; BackgroundColor = Color.White;// Color.Transparent; _currentSpanStyle = new TextSpanStyle(); _currentSpanStyle.FontColor = Color.Black;//set default _currentSpanStyle.ReqFont = rootgfx.DefaultTextEditFontInfo; // _textLayer = new EditableTextFlowLayer(this); //presentation _internalTextLayerController = new InternalTextLayerController(_textLayer); //controller _isMultiLine = isMultiLine; if (isMultiLine) { _textLayer.SetUseDoubleCanvas(false, true); } else { _textLayer.SetUseDoubleCanvas(true, false); } NeedClipArea = true; IsBlockElement = false; NumOfWhitespaceForSingleTab = 4;//default?, configurable? }
public SolidTextRun(RootGraphic gfx, string str, TextSpanStyle style) : base(gfx) { _spanStyle = style; if (str != null && str.Length > 0) { _mybuffer = str.ToCharArray(); if (_mybuffer.Length == 1 && _mybuffer[0] == '\n') { this.IsLineBreak = true; } UpdateRunWidth(); } else { throw new Exception("string must be null or zero length"); } }
protected PixelFarm.Drawing.RequestFont GetFont() { if (!HasStyle) { return(this.Root.DefaultTextEditFontInfo); } else { TextSpanStyle spanStyle = this.SpanStyle; if (spanStyle.ReqFont != null) { return(spanStyle.ReqFont); } else { return(this.Root.DefaultTextEditFontInfo); } } }
public EditableTextRun(RootGraphic gfx, string str, TextSpanStyle style) : base(gfx) { _spanStyle = style; if (str != null && str.Length > 0) { SetNewContent(str.ToCharArray()); //special treament if (_mybuffer.Length == 1 && _mybuffer[0] == '\n') { this.IsLineBreak = true; } UpdateRunWidth(); } else { //TODO: review here throw new Exception("string must be null or zero length"); } }
// public override void CustomDrawToThisCanvas(DrawBoard canvas, Rectangle updateArea) { int bWidth = this.Width; int bHeight = this.Height; #if DEBUG //canvas.dbug_DrawCrossRect(Color.Red, new Rectangle(0, 0, bWidth, bHeight)); //canvas.DrawRectangle(Color.Red, 0, 0, bWidth, bHeight); #endif if (!this.HasStyle) { canvas.DrawText(_mybuffer, new Rectangle(0, 0, bWidth, bHeight), 0); } else { TextSpanStyle style = this.SpanStyle; switch (EvaluateFontAndTextColor(canvas, style)) { case DIFF_FONT_SAME_TEXT_COLOR: { canvas.DrawText(_mybuffer, new Rectangle(0, 0, bWidth, bHeight), style.ContentHAlign); } break; case DIFF_FONT_DIFF_TEXT_COLOR: { RequestFont prevFont = canvas.CurrentFont; Color prevColor = canvas.CurrentTextColor; canvas.CurrentFont = style.ReqFont; canvas.CurrentTextColor = style.FontColor; canvas.DrawText(_mybuffer, new Rectangle(0, 0, bWidth, bHeight), style.ContentHAlign); canvas.CurrentFont = prevFont; canvas.CurrentTextColor = prevColor; } break; case SAME_FONT_DIFF_TEXT_COLOR: { Color prevColor = canvas.CurrentTextColor; canvas.CurrentTextColor = style.FontColor; canvas.DrawText(_mybuffer, new Rectangle(0, 0, bWidth, bHeight), style.ContentHAlign); canvas.CurrentTextColor = prevColor; } break; default: { canvas.DrawText(_mybuffer, new Rectangle(0, 0, bWidth, bHeight), style.ContentHAlign); } break; } } }
public abstract void SetStyle(TextSpanStyle spanStyle);