/// <summary> /// Prints the selection. /// </summary> public virtual void Print() { ILayoutNodeState State = StateView.State; ILayoutBlockListInner ParentInner = State.PropertyToInner(PropertyName) as ILayoutBlockListInner; Debug.Assert(ParentInner != null); Debug.Assert(BlockIndex >= 0 && BlockIndex < ParentInner.BlockStateList.Count); ILayoutBlockState BlockState = ParentInner.BlockStateList[BlockIndex]; ILayoutControllerView ControllerView = StateView.ControllerView; Debug.Assert(ControllerView.PrintContext != null); ControllerView.UpdateLayout(); Debug.Assert(StartIndex <= EndIndex); ILayoutNodeStateView FirstStateView = ControllerView.StateViewTable[BlockState.StateList[StartIndex]]; Point Origin = FirstStateView.CellOrigin.Opposite; for (int i = StartIndex; i < EndIndex; i++) { ILayoutNodeStateView StateView = ControllerView.StateViewTable[BlockState.StateList[i]]; Debug.Assert(RegionHelper.IsValid(StateView.ActualCellSize)); StateView.PrintCells(Origin); } }
/// <summary> /// Reads <paramref name="sourceStream"/> as an easly source code and from it create a bitmap using the BMP format in <paramref name="destinationStream"/>. /// </summary> /// <param name="sourceStream">The source code.</param> /// <param name="destinationStream">The destination bitmap.</param> /// <returns></returns> private static int PreviewFile(FileStream sourceStream, FileStream destinationStream) { // Create a serializer than can read text or binary formats. Serializer Serializer = new Serializer(); Serializer.Format = SerializationFormat.BinaryPreferred; // Reads the source stream as an easly source code. INode RootNode = Serializer.Deserialize(sourceStream) as INode; // Create a controller for this source code. ILayoutRootNodeIndex RootIndex = new LayoutRootNodeIndex(RootNode); ILayoutController Controller = LayoutController.Create(RootIndex); Size ViewSize; // Create and open a visual on which to render. DrawingVisual DrawingVisual = new DrawingVisual(); using (DrawingContext dc = DrawingVisual.RenderOpen()) { // Create a draw context using default fonts and brushes. DrawContext DrawContext = DrawContext.CreateDrawContext(new Typeface("Consolas"), 10, CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, null, null, hasCommentIcon: true, displayFocus: true); // Create a view using custom frames (for how code is organized). ILayoutControllerView ControllerView = LayoutControllerView.Create(Controller, EaslyEdit.CustomLayoutTemplateSet.LayoutTemplateSet, DrawContext); ControllerView.SetCommentDisplayMode(EaslyController.Constants.CommentDisplayModes.All); // Run the measure step to obtain the bitmap size. ControllerView.MeasureAndArrange(); ViewSize = ControllerView.ViewSize; // Draw a white background. dc.DrawRectangle(Brushes.White, null, new System.Windows.Rect(0, 0, ViewSize.Width.Draw, ViewSize.Height.Draw)); // Draw the source code. DrawContext.SetWpfDrawingContext(dc); ControllerView.Draw(ControllerView.RootStateView); } // At this stage, the visual is ready with drawing data. // Create a bitmap and renders the visual on it. RenderTargetBitmap Bitmap = new RenderTargetBitmap((int)ViewSize.Width.Draw, (int)ViewSize.Height.Draw, Dpi, Dpi, PixelFormats.Default); Bitmap.Render(DrawingVisual); // Save the bitmap to the destination file with a BMP format encoder. BmpBitmapEncoder Encoder = new BmpBitmapEncoder(); BitmapFrame Frame = BitmapFrame.Create(Bitmap); Encoder.Frames.Add(Frame); Encoder.Save(destinationStream); return(0); }
/// <summary> /// Prints the selection. /// </summary> public virtual void Print() { ILayoutControllerView ControllerView = StateView.ControllerView; Debug.Assert(ControllerView.PrintContext != null); ControllerView.UpdateLayout(); Debug.Assert(RegionHelper.IsValid(StateView.ActualCellSize)); Point Origin = StateView.CellOrigin.Opposite; StateView.PrintCells(Origin); }
/// <summary> /// Draws a cell created with this frame. /// </summary> /// <param name="drawContext">The context used to draw the cell.</param> /// <param name="cellView">The cell to draw.</param> /// <param name="origin">The location where to start drawing.</param> /// <param name="size">The drawing size, padding included.</param> /// <param name="padding">The padding to use when drawing.</param> public virtual void Draw(ILayoutDrawContext drawContext, ILayoutCellView cellView, Point origin, Size size, Padding padding) { ILayoutCommentCellView CommentCellView = cellView as ILayoutCommentCellView; Debug.Assert(CommentCellView != null); string Text = CommentHelper.Get(CommentCellView.Documentation); CommentDisplayModes DisplayMode = cellView.StateView.ControllerView.CommentDisplayMode; Debug.Assert(DisplayMode == CommentDisplayModes.OnFocus || DisplayMode == CommentDisplayModes.All); bool IsFocused = cellView.StateView.ControllerView.Focus.CellView == cellView; if (IsFocused && Text == null) { Text = string.Empty; } if (Text != null) { if ((DisplayMode == CommentDisplayModes.OnFocus && IsFocused) || DisplayMode == CommentDisplayModes.All) { Point OriginWithPadding = origin.Moved(padding.Left, padding.Top); drawContext.DrawTextBackground(Text, OriginWithPadding, TextStyles.Comment); ILayoutControllerView ControllerView = cellView.StateView.ControllerView; if (ControllerView.Selection is ILayoutCommentSelection AsCommentSelection && AsCommentSelection.StateView == cellView.StateView) { int Start = AsCommentSelection.Start; int End = AsCommentSelection.End; Debug.Assert(Start <= End); drawContext.DrawSelectionText(Text, OriginWithPadding, TextStyles.Comment, Start, End); } drawContext.DrawText(Text, OriginWithPadding, TextStyles.Comment, isFocused: false); // The caret is drawn separately. } else if (DisplayMode == CommentDisplayModes.OnFocus && cellView.StateView.ControllerView.ShowUnfocusedComments) { drawContext.DrawCommentIcon(new Rect(cellView.CellOrigin, Size.Empty)); } } }
/// <summary> /// Prints the selection. /// </summary> public virtual void Print() { ILayoutControllerView ControllerView = StateView.ControllerView; Debug.Assert(ControllerView.PrintContext != null); ControllerView.UpdateLayout(); Debug.Assert(RegionHelper.IsValid(StateView.ActualCellSize)); ILayoutTemplateSet TemplateSet = ControllerView.TemplateSet; IList <IFocusFrameSelectorList> SelectorStack = StateView.GetSelectorStack(); ILayoutDiscreteFrame Frame = (ILayoutDiscreteFrame)TemplateSet.PropertyToFrame(StateView.State, PropertyName, SelectorStack); Debug.Assert(Frame != null); int Value = NodeTreeHelper.GetEnumValue(StateView.State.Node, PropertyName); Frame.Print(ControllerView.PrintContext, Value, Point.Origin); }
/// <summary> /// Draws a cell created with this frame. /// </summary> /// <param name="drawContext">The context used to draw the cell.</param> /// <param name="cellView">The cell to draw.</param> /// <param name="origin">The location where to start drawing.</param> /// <param name="size">The drawing size, padding included.</param> /// <param name="padding">The padding to use when drawing.</param> public virtual void Draw(ILayoutDrawContext drawContext, ILayoutCellView cellView, Point origin, Size size, Padding padding) { INode Node = cellView.StateView.State.Node; string Text = BaseNodeHelper.NodeTreeHelper.GetString(Node, PropertyName); Point OriginWithPadding = origin.Moved(padding.Left, padding.Top); drawContext.DrawTextBackground(Text, OriginWithPadding, TextStyle); ILayoutControllerView ControllerView = cellView.StateView.ControllerView; if (ControllerView.Selection is ILayoutStringContentSelection AsStringContentSelection && AsStringContentSelection.StateView == cellView.StateView) { int Start = AsStringContentSelection.Start; int End = AsStringContentSelection.End; Debug.Assert(Start <= End); drawContext.DrawSelectionText(Text, OriginWithPadding, TextStyle, Start, End); } drawContext.DrawText(Text, OriginWithPadding, TextStyle, isFocused: false); // The caret is drawn separately. }
/// <summary> /// Prints the selection. /// </summary> public virtual void Print() { ILayoutControllerView ControllerView = StateView.ControllerView; Debug.Assert(ControllerView.PrintContext != null); ControllerView.UpdateLayout(); Debug.Assert(RegionHelper.IsValid(StateView.ActualCellSize)); ILayoutTemplateSet TemplateSet = ControllerView.TemplateSet; IList <IFocusFrameSelectorList> SelectorStack = StateView.GetSelectorStack(); ILayoutTextValueFrame Frame = (ILayoutTextValueFrame)TemplateSet.PropertyToFrame(StateView.State, PropertyName, SelectorStack); Debug.Assert(Frame != null); string Text = NodeTreeHelper.GetString(StateView.State.Node, PropertyName); Debug.Assert(Text != null); Debug.Assert(Start <= End); Debug.Assert(End <= Text.Length); Frame.Print(ControllerView.PrintContext, Text.Substring(Start, End - Start), Point.Origin); }
/// <summary> /// Initializes a new instance of the <see cref="LayoutCellViewTreeContext"/> class. /// </summary> /// <param name="controllerView">The view in which cells are created.</param> /// <param name="stateView">The state view for which to create cells.</param> /// <param name="forcedCommentStateView">The state view for which the comment must be visible, even if empty.</param> public LayoutCellViewTreeContext(ILayoutControllerView controllerView, ILayoutNodeStateView stateView, ILayoutNodeStateView forcedCommentStateView) : base(controllerView, stateView, forcedCommentStateView) { }