VectSharp  2.2.1
A light library for C# vector graphics
MarkdownContext.cs
1 /*
2  VectSharp - A light library for C# vector graphics.
3  Copyright (C) 2020-2022 Giorgio Bianchini
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, version 3.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 using System;
19 using System.Collections.Generic;
20 using System.Text;
21 
22 namespace VectSharp.Markdown
23 {
24  internal class MarkdownContext
25  {
26  public Font Font { get; set; }
27 
28  private Point cursor;
29  public Point Cursor
30  {
31  get
32  {
33  return cursor;
34  }
35 
36  set
37  {
38  cursor = value;
39 
40  double maxX = Math.Max(BottomRight.X, value.X + Translation.X);
41  double maxY = Math.Max(BottomRight.Y, value.Y + Translation.Y);
42 
43  this.BottomRight = new Point(maxX, maxY);
44  }
45  }
46 
47  public Colour Colour { get; set; }
48  public bool Underline { get; set; }
49  public bool StrikeThrough { get; set; }
50 
51  private Point translation;
52  public Point Translation
53  {
54  get
55  {
56  return translation;
57  }
58 
59  set
60  {
61  translation = value;
62 
63  double maxX = Math.Max(BottomRight.X, cursor.X + value.X);
64  double maxY = Math.Max(BottomRight.Y, cursor.Y + value.Y);
65 
66  this.BottomRight = new Point(maxX, maxY);
67  }
68  }
69 
70  public Point MarginBottomRight { get; set; }
71 
72  public Line CurrentLine { get; set; }
73  public int ListDepth { get; set; }
74  public List<(double MaxX, double MinY, double MaxY)> ForbiddenAreasRight { get; set; }
75  public List<(double MinX, double MinY, double MaxY)> ForbiddenAreasLeft { get; set; }
76  public Page CurrentPage { get; set; }
77  public Point BottomRight { get; set; }
78  public string Tag { get; set; } = null;
79  public Dictionary<string, string> LinkDestinations { get; set; } = new Dictionary<string, string>();
80  public Dictionary<string, string> InternalAnchors { get; set; } = new Dictionary<string, string>();
81 
82  public MarkdownContext()
83  {
84  this.ForbiddenAreasRight = new List<(double MaxX, double MinY, double MaxY)>();
85  this.ForbiddenAreasLeft = new List<(double MinX, double MinY, double MaxY)>();
86  }
87 
88  public MarkdownContext Clone()
89  {
90  return new MarkdownContext()
91  {
92  Font = this.Font,
93  Cursor = this.Cursor,
94  Colour = this.Colour,
95  Underline = this.Underline,
96  StrikeThrough = this.StrikeThrough,
97  Translation = this.Translation,
98  CurrentLine = this.CurrentLine,
99  ListDepth = this.ListDepth,
100  ForbiddenAreasRight = this.ForbiddenAreasRight,
101  ForbiddenAreasLeft = this.ForbiddenAreasLeft,
102  CurrentPage = this.CurrentPage,
103  Tag = this.Tag,
104  LinkDestinations = this.LinkDestinations,
105  InternalAnchors = this.InternalAnchors,
106  MarginBottomRight = this.MarginBottomRight
107  };
108  }
109 
110  public double GetMaxX(double y, double pageMaxX)
111  {
112  y = y + Translation.Y;
113 
114  double maxX = pageMaxX;
115 
116  foreach ((double MaxX, double MinY, double MaxY) in ForbiddenAreasRight)
117  {
118  if (MinY <= y && MaxY >= y)
119  {
120  maxX = Math.Min(maxX, MaxX - this.Translation.X);
121  }
122  }
123 
124  return maxX;
125  }
126 
127  public double GetMaxX(double y0, double y1, double pageMaxX)
128  {
129  y0 = y0 + Translation.Y;
130  y1 = y1 + Translation.Y;
131 
132  double maxX = pageMaxX;
133 
134  foreach ((double MaxX, double MinY, double MaxY) in ForbiddenAreasRight)
135  {
136  if (!((MinY < y0 && MaxY < y0) || (MinY > y1 && MaxY > y1)))
137  {
138  maxX = Math.Min(maxX, MaxX - this.Translation.X);
139  }
140  }
141 
142  return maxX;
143  }
144 
145  public double GetMinX(double y)
146  {
147  y = y + Translation.Y;
148 
149  double minX = 0;
150 
151  foreach ((double MinX, double MinY, double MaxY) in ForbiddenAreasLeft)
152  {
153  if (MinY <= y && MaxY >= y)
154  {
155  minX = Math.Max(minX, MinX - Translation.X);
156  }
157  }
158 
159  return minX;
160  }
161 
162  public double GetMinX(double y0, double y1)
163  {
164 
165  y0 = y0 + Translation.Y;
166  y1 = y1 + Translation.Y;
167 
168  double minX = 0;
169 
170  foreach ((double MinX, double MinY, double MaxY) in ForbiddenAreasLeft)
171  {
172  if (!((MinY < y0 && MaxY < y0) || (MinY > y1 && MaxY > y1)))
173  {
174  minX = Math.Max(minX, MinX - Translation.X);
175  }
176  }
177 
178  return minX;
179  }
180  }
181 
182  /// <summary>
183  /// Represents the margins of a page.
184  /// </summary>
185  public class Margins
186  {
187  /// <summary>
188  /// The left margin.
189  /// </summary>
190  public double Left { get; }
191 
192  /// <summary>
193  /// The right margin.
194  /// </summary>
195  public double Right { get; }
196 
197  /// <summary>
198  /// The top margin.
199  /// </summary>
200  public double Top { get; }
201 
202  /// <summary>
203  /// The bottom margin.
204  /// </summary>
205  public double Bottom { get; }
206 
207  /// <summary>
208  /// Creates a new <see cref="Margins"/> instance.
209  /// </summary>
210  /// <param name="left">The left margin.</param>
211  /// <param name="top">The top margin.</param>
212  /// <param name="right">The right margin.</param>
213  /// <param name="bottom">The bottom margin.</param>
214  public Margins(double left, double top, double right, double bottom)
215  {
216  this.Left = left;
217  this.Right = right;
218  this.Top = top;
219  this.Bottom = bottom;
220  }
221  }
222 }
VectSharp.Markdown.Margins.Bottom
double Bottom
The bottom margin.
Definition: MarkdownContext.cs:205
VectSharp.Markdown.Margins.Margins
Margins(double left, double top, double right, double bottom)
Creates a new Margins instance.
Definition: MarkdownContext.cs:214
VectSharp.Markdown.Margins.Right
double Right
The right margin.
Definition: MarkdownContext.cs:195
VectSharp.Markdown.Margins.Top
double Top
The top margin.
Definition: MarkdownContext.cs:200
VectSharp.SegmentType.Line
@ Line
The segment represents a straight line from the current point to a new point.
VectSharp.Markdown
Definition: HtmlTag.cs:26
VectSharp.Markdown.Margins
Represents the margins of a page.
Definition: MarkdownContext.cs:186
VectSharp.Markdown.Margins.Left
double Left
The left margin.
Definition: MarkdownContext.cs:190