Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Feb 12, 2025
2 parents 6dc992f + e2f80d9 commit 29461b3
Show file tree
Hide file tree
Showing 22 changed files with 406 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ public virtual void NoObjectBoundingBoxTest() {
SvgTagSvgNodeRenderer renderer = new SvgTagSvgNodeRenderer();
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(null));
}

[NUnit.Framework.Test]
public virtual void CanConstructViewPortTest() {
SvgTagSvgNodeRenderer renderer = new SvgTagSvgNodeRenderer();
NUnit.Framework.Assert.IsTrue(renderer.CanConstructViewPort());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ public virtual void NoObjectBoundingBoxTest() {
SymbolSvgNodeRenderer renderer = new SymbolSvgNodeRenderer();
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(null));
}

[NUnit.Framework.Test]
public virtual void CanConstructViewPortTest() {
SymbolSvgNodeRenderer renderer = new SymbolSvgNodeRenderer();
NUnit.Framework.Assert.IsTrue(renderer.CanConstructViewPort());
}
}
}
26 changes: 26 additions & 0 deletions itext/itext.svg/itext/svg/css/impl/SvgStyleResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ public SvgStyleResolver(INode rootNode, SvgProcessorContext context) {
CollectFonts();
}

/// <summary>Resolves the font size stored inside the current element.</summary>
/// <param name="styles">attributes map of the current element</param>
/// <param name="cssContext">
///
/// <see cref="iText.Svg.Css.SvgCssContext"/>
/// instance in order to resolve relative font size
/// </param>
/// <param name="parentFontSizeStr">parent font size value</param>
public static void ResolveFontSizeStyle(IDictionary<String, String> styles, SvgCssContext cssContext, String
parentFontSizeStr) {
String elementFontSize = styles.Get(SvgConstants.Attributes.FONT_SIZE);
Expand Down Expand Up @@ -166,6 +174,24 @@ public static void ResolveFontSizeStyle(IDictionary<String, String> styles, SvgC
styles.Put(SvgConstants.Attributes.FONT_SIZE, resolvedFontSize + CommonCssConstants.PT);
}

/// <summary>Checks whether element is nested within the passed parent element.</summary>
/// <remarks>
/// Checks whether element is nested within the passed parent element. Nesting is checked at several levels
/// (recursively).
/// </remarks>
/// <param name="element">
///
/// <see cref="iText.StyledXmlParser.Node.IElementNode"/>
/// element to check
/// </param>
/// <param name="parentElementNameForSearch">expected parent element name</param>
/// <returns>
///
/// <see langword="true"/>
/// if element is nested within the expected parent,
/// <see langword="false"/>
/// otherwise
/// </returns>
public static bool IsElementNested(IElementNode element, String parentElementNameForSearch) {
if (!(element.ParentNode() is IElementNode)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,34 @@ public virtual void SetCustomViewport(Rectangle customViewport) {
this.customViewport = customViewport;
}

/// <summary>Sets renderer factory.</summary>
/// <param name="rendererFactory">
///
/// <see cref="iText.Svg.Renderers.Factories.ISvgNodeRendererFactory"/>
/// to set
/// </param>
/// <returns>
/// this
/// <see cref="SvgConverterProperties"/>
/// instance
/// </returns>
public virtual iText.Svg.Processors.Impl.SvgConverterProperties SetRendererFactory(ISvgNodeRendererFactory
rendererFactory) {
this.rendererFactory = rendererFactory;
return this;
}

/// <summary>Sets font provider.</summary>
/// <param name="fontProvider">
///
/// <see cref="iText.Layout.Font.FontProvider"/>
/// to set
/// </param>
/// <returns>
/// this
/// <see cref="SvgConverterProperties"/>
/// instance
/// </returns>
public virtual iText.Svg.Processors.Impl.SvgConverterProperties SetFontProvider(FontProvider fontProvider) {
this.fontProvider = fontProvider;
return this;
Expand All @@ -116,6 +138,13 @@ public virtual String GetCharset() {
return charset;
}

/// <summary>Sets the character set.</summary>
/// <param name="charset">the character set to set</param>
/// <returns>
/// this
/// <see cref="SvgConverterProperties"/>
/// instance
/// </returns>
public virtual iText.Svg.Processors.Impl.SvgConverterProperties SetCharset(String charset) {
this.charset = charset;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ You should have received a copy of the GNU Affero General Public License
namespace iText.Svg.Processors.Impl.Font {
/// <summary>Class that processes and add resolved css fonts to the FontProvider</summary>
public class SvgFontProcessor {
private SvgProcessorContext context;
private readonly SvgProcessorContext context;

/// <summary>
/// Creates new
/// <see cref="SvgFontProcessor"/>
/// instance.
/// </summary>
/// <param name="context">
///
/// <see cref="iText.Svg.Processors.Impl.SvgProcessorContext"/>
/// to add resolved fonts to
/// </param>
public SvgFontProcessor(SvgProcessorContext context) {
this.context = context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Svg.Utils;

namespace iText.Svg.Renderers.Impl {
/// <summary>Abstract class that will be the superclass for any element that instantiates new view port.</summary>
public abstract class AbstractContainerSvgNodeRenderer : AbstractBranchSvgNodeRenderer {
public override bool CanConstructViewPort() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ You should have received a copy of the GNU Affero General Public License
using iText.Svg.Renderers;

namespace iText.Svg.Renderers.Impl {
/// <summary>
/// <see cref="iText.Svg.Renderers.ISvgNodeRenderer"/>
/// implementation for the &lt;defs&gt; tag.
/// </summary>
public class DefsSvgNodeRenderer : AbstractBranchSvgNodeRenderer, INoDrawSvgNodeRenderer {
protected internal override void DoDraw(SvgDrawContext context) {
throw new NotSupportedException(SvgExceptionMessageConstant.DRAW_NO_DRAW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ You should have received a copy of the GNU Affero General Public License
using iText.Svg.Utils;

namespace iText.Svg.Renderers.Impl {
/// <summary>Interface for &lt;text&gt; and &lt;tspan&gt; related renderers.</summary>
public interface ISvgTextNodeRenderer : ISvgNodeRenderer {
/// <summary>Gets text content length.</summary>
/// <param name="parentFontSize">parent font size</param>
/// <param name="font">current font</param>
/// <returns>text content length</returns>
[Obsolete]
float GetTextContentLength(float parentFontSize, PdfFont font);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,26 @@ namespace iText.Svg.Renderers.Impl {
/// implementation for the &lt;polyline&gt; tag.
/// </summary>
public class PolylineSvgNodeRenderer : AbstractSvgNodeRenderer, IMarkerCapable {
/// <summary>orientation vector which is used for marker angle calculation.</summary>
/// <summary>Orientation vector which is used for marker angle calculation.</summary>
private Vector previousOrientationVector = new Vector(1, 0, 0);

/// <summary>
/// A List of
/// <see cref="iText.Kernel.Geom.Point"/>
/// objects representing the path to be drawn by the polyline tag
/// objects representing the path to be drawn by the polyline tag.
/// </summary>
protected internal IList<Point> points = new List<Point>();

/// <summary>
/// Returns a list of
/// <see cref="iText.Kernel.Geom.Point"/>
/// objects representing the path to be drawn by the polyline tag.
/// </summary>
/// <returns>
/// a list of
/// <see cref="iText.Kernel.Geom.Point"/>
/// objects
/// </returns>
protected internal virtual IList<Point> GetPoints() {
return this.points;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ You should have received a copy of the GNU Affero General Public License
using iText.Svg.Renderers;

namespace iText.Svg.Renderers.Impl {
/// <summary>
/// <see cref="iText.Svg.Renderers.ISvgNodeRenderer"/>
/// implementation for the &lt;symbol&gt; tag.
/// </summary>
public class SymbolSvgNodeRenderer : AbstractContainerSvgNodeRenderer, INoDrawSvgNodeRenderer {
public override ISvgNodeRenderer CreateDeepCopy() {
SymbolSvgNodeRenderer copy = new SymbolSvgNodeRenderer();
Expand Down
76 changes: 76 additions & 0 deletions itext/itext.svg/itext/svg/renderers/impl/TextSvgBranchRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public class TextSvgBranchRenderer : AbstractSvgNodeRenderer, ISvgTextNodeRender

private bool whiteSpaceProcessed = false;

/// <summary>
/// Creates new
/// <see cref="TextSvgBranchRenderer"/>
/// instance.
/// </summary>
public TextSvgBranchRenderer() {
performRootTransformations = true;
moveResolved = false;
Expand All @@ -90,13 +95,33 @@ internal virtual void FillCopy(iText.Svg.Renderers.Impl.TextSvgBranchRenderer co
}
//\endcond

/// <summary>
/// Adds a child to the current
/// <see cref="TextSvgBranchRenderer"/>
/// renderer.
/// </summary>
/// <param name="child">
///
/// <see cref="ISvgTextNodeRenderer"/>
/// child to add
/// </param>
public void AddChild(ISvgTextNodeRenderer child) {
// Final method, in order to disallow adding null
if (child != null) {
children.Add(child);
}
}

/// <summary>
/// Retrieves a list of all children of the current
/// <see cref="TextSvgBranchRenderer"/>
/// renderer.
/// </summary>
/// <returns>
/// a list of
/// <see cref="ISvgTextNodeRenderer"/>
/// children
/// </returns>
public IList<ISvgTextNodeRenderer> GetChildren() {
// Final method, in order to disallow modifying the List
return JavaCollectionsUtil.UnmodifiableList(children);
Expand All @@ -113,6 +138,18 @@ public virtual float[] GetRelativeTranslation() {
return GetRelativeTranslation(new SvgDrawContext(null, null));
}

/// <summary>Gets relative translation of the current &lt;text&gt; or &lt;tspan&gt; element.</summary>
/// <param name="context">
/// current
/// <see cref="iText.Svg.Renderers.SvgDrawContext"/>
/// </param>
/// <returns>
/// float array that contains relative
/// <c>dx</c>
/// and
/// <c>dy</c>
/// translations
/// </returns>
public virtual float[] GetRelativeTranslation(SvgDrawContext context) {
if (!moveResolved) {
ResolveRelativeTextMove(context);
Expand All @@ -125,6 +162,18 @@ public virtual bool ContainsRelativeMove() {
return ContainsRelativeMove(new SvgDrawContext(null, null));
}

/// <summary>Checks whether current &lt;text&gt; or &lt;tspan&gt; element contains relative position change.</summary>
/// <param name="context">
/// current
/// <see cref="iText.Svg.Renderers.SvgDrawContext"/>
/// </param>
/// <returns>
///
/// <see langword="true"/>
/// is current element contains relative position,
/// <see langword="false"/>
/// otherwise
/// </returns>
public virtual bool ContainsRelativeMove(SvgDrawContext context) {
if (!moveResolved) {
ResolveRelativeTextMove(context);
Expand All @@ -138,6 +187,19 @@ public virtual bool ContainsAbsolutePositionChange() {
return ContainsAbsolutePositionChange(new SvgDrawContext(null, null));
}

/// <summary>Checks whether current &lt;text&gt; or &lt;tspan&gt; element contains absolute position attributes.
/// </summary>
/// <param name="context">
/// current
/// <see cref="iText.Svg.Renderers.SvgDrawContext"/>
/// </param>
/// <returns>
///
/// <see langword="true"/>
/// is current element contains absolute position,
/// <see langword="false"/>
/// otherwise
/// </returns>
public virtual bool ContainsAbsolutePositionChange(SvgDrawContext context) {
if (!posResolved) {
ResolveAbsoluteTextPosition(context);
Expand All @@ -149,13 +211,27 @@ public virtual float[][] GetAbsolutePositionChanges() {
return GetAbsolutePositionChanges(new SvgDrawContext(null, null));
}

/// <summary>Gets absolute position of the current &lt;text&gt; or &lt;tspan&gt; element.</summary>
/// <param name="context">
/// current
/// <see cref="iText.Svg.Renderers.SvgDrawContext"/>
/// </param>
/// <returns>
/// float array that contains absolute
/// <c>x</c>
/// and
/// <c>y</c>
/// positions as either single item arrays
/// or null if attribute is not present
/// </returns>
public virtual float[][] GetAbsolutePositionChanges(SvgDrawContext context) {
if (!posResolved) {
ResolveAbsoluteTextPosition(context);
}
return new float[][] { xPos, yPos };
}

/// <summary>Marks white-space property as processed.</summary>
public virtual void MarkWhiteSpaceProcessed() {
whiteSpaceProcessed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ You should have received a copy of the GNU Affero General Public License
using iText.Svg.Renderers;

namespace iText.Svg.Renderers.Impl {
/// <summary>
/// <see cref="iText.Svg.Renderers.ISvgNodeRenderer"/>
/// implementation for the &lt;tspan&gt; tag.
/// </summary>
public class TextSvgTSpanBranchRenderer : TextSvgBranchRenderer {
/// <summary>
/// Creates new
/// <see cref="TextSvgTSpanBranchRenderer"/>
/// instance.
/// </summary>
public TextSvgTSpanBranchRenderer() {
this.performRootTransformations = false;
}
Expand Down
11 changes: 10 additions & 1 deletion itext/itext.svg/itext/svg/renderers/path/IPathShapeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ public interface IPathShapeMapper {
/// <returns>
/// a
/// <see cref="System.Collections.IDictionary{K, V}"/>
/// with Strings as keys and {link @
/// with Strings as keys and
/// <see cref="IPathShape"/>
/// implementations as values
/// </returns>
IDictionary<String, IPathShape> GetMapping();

/// <summary>
/// Provides a mapping of SVG path element's path-data instruction name to the appropriate number of arguments
/// for a path command, based on this passed SVG path data instruction tag.
/// </summary>
/// <returns>
/// a
/// <see cref="System.Collections.IDictionary{K, V}"/>
/// with Strings as keys and Integers as values
/// </returns>
IDictionary<String, int?> GetArgumentCount();
}
}
Loading

0 comments on commit 29461b3

Please sign in to comment.