Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Graphics class and every related class, struct and enum #20

Open
wants to merge 220 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
220 commits
Select commit Hold shift + click to select a range
f95d003
add Matrix class
Jul 17, 2024
8ea181b
add StringFormat class and referenced enum/classes
Jul 17, 2024
a33518b
add GraphicsPath and its dependencies (except for Pen, Brush and Grap…
Jul 17, 2024
d585997
add Brush class
Jul 17, 2024
4669b61
add SolidBrush class
Jul 17, 2024
f02453e
add Brushes class
Jul 17, 2024
9944486
add TextureBrush class and WrapMode enum
Jul 17, 2024
9f6c0e9
add HatchBrush style and HatchStyle enum
Jul 17, 2024
c7b826f
add LinearGradientBrush class and referenced enum/classes
Jul 17, 2024
693b07a
add PathGradientBrush class
Jul 17, 2024
457314d
add Pen class and referenced enums
Jul 17, 2024
3c43ad0
add GraphicsPath class methods' implementation depending on Pen and B…
Jul 17, 2024
0e10e8e
add Region class and RegionDataClass class, update RectangleF with re…
Jul 18, 2024
0b96006
add Graphics and referenced enum/class, update references from other …
Jul 18, 2024
78d2357
fix indentation spaces by tabs
Jul 18, 2024
f2a2852
fix Region.GetBounds signature and fix error when Graphics parameter …
Jul 18, 2024
ccf6283
fix methods depending on Graphics class (TODOs)
Jul 18, 2024
b5d07bf
add Region class test-cases
Jul 18, 2024
a48994a
fix Region.IsVisible method considering Graphics parameter
Jul 18, 2024
b8978e4
minor: remove unrequired usings in tests
Jul 19, 2024
f18809d
define PathPointType as byte
Jul 22, 2024
fe6666f
fix infinite recursion
Jul 22, 2024
e7b43ad
define helper methods as private
Jul 22, 2024
ad8f362
fix IsVisible and IsOutlineVisible helper methods
Jul 22, 2024
2e3ed4d
fix GetBound method
Jul 22, 2024
8ba0726
fix PathType property and CreatePath helper method
Jul 22, 2024
f77c4a9
minor fix
Jul 22, 2024
8e9ac8f
fix AddBezier helper method
Jul 22, 2024
6b1acb4
fix AddLine helper method
Jul 22, 2024
4d5bfef
fix AddPie helper method
Jul 22, 2024
4b9b28d
fix AddCurve and AddEllipse helper methods visibility
Jul 22, 2024
6187ee1
fix AddCurve helper method
Jul 22, 2024
89f9cc6
minor indentation fix
Jul 22, 2024
8f4b335
implement Flatten method
Jul 22, 2024
24d8237
simplify Flatten method
Jul 22, 2024
cd7f607
improve performance in Matrix.TransformPoints method
Jul 23, 2024
3ef0eb1
fix GraphicsPath.PathTypes property
Jul 24, 2024
44f2835
add GraphicsPath.ToSvg extra method
Jul 24, 2024
9e3e394
fix GtaphicsPath.PathTypes property
Jul 24, 2024
53b957e
fix GraphicsPath.Flatten method
Jul 24, 2024
f517540
add using in GraphicsPath.Reverse method
Jul 24, 2024
77c29bf
remove comment
Jul 24, 2024
a60a427
minor change
Jul 24, 2024
10245cb
add unit test for GraphicsPath class
Jul 24, 2024
320644e
minor changes in test cases for Region and GraphicsPath
Jul 25, 2024
af2fdd0
change definition for Pen properties: DashCap, DashOffset, DashPatter…
Jul 25, 2024
b196009
init proper values in Pen class
Jul 25, 2024
8eb90a1
minor improvement on exception message for Pen.Aligment property
Jul 25, 2024
5816f0c
fix Pen.Brush property behaviour
Jul 25, 2024
a0951eb
fix Pen.Clone method
Jul 25, 2024
b79742f
add Pen unit test
Jul 25, 2024
d1fa466
minor change in PenUnitTest class
Jul 25, 2024
85f26d4
fix clone method unit test for several classes
Jul 25, 2024
2396f83
add SolidBrushUnitTest
Jul 25, 2024
0de69a1
minor change
Jul 25, 2024
ef69797
update TestureBrush for supporing RectangleF and Image classes, and d…
Jul 25, 2024
f2ba408
add HatchBrush constructor summary and missing constructor (without b…
Jul 25, 2024
3ae755c
change CreateShader by UpdateShader in HatchBrush class
Jul 25, 2024
da39321
add TextureBrushUnitTest
Jul 25, 2024
c73fe32
change indentation by tabs in Pen class
Jul 25, 2024
64cca1c
fix TextureBrush.Clone method
Jul 25, 2024
e04e3f2
minor change in SolidBrushUnitTest
Jul 25, 2024
9b86273
add unit test for Clone method in TextureBrushUnitTest
Jul 25, 2024
6ae48f1
add HatchBrushUnitTest
Jul 25, 2024
250bb7f
minor change
Jul 25, 2024
4f43983
add validation to InterpolationColors in LinearGradientBrush
Jul 26, 2024
63d1ca7
fix LinearGradientBrush constructor
Jul 26, 2024
b1d62a0
check null in InterpolationColors of LinearGradientBrush
Jul 26, 2024
6b3f43e
fix UpdateShader of LinearGradientBrush based on factor and color blends
Jul 26, 2024
7286994
implement SetSigmaBellShape and SetBlendTriangularShape methdos of Li…
Jul 26, 2024
618ff2d
fix SigmaBellBlend helper in LinearGradientBrush
Jul 26, 2024
2a96734
fix LinearGradientBrush class
Jul 29, 2024
58786fe
add LinearGradientBrush unit test
Jul 29, 2024
2e8d558
minor fix in namespace for Utils class
Jul 29, 2024
710866e
improve SolidBrush unit test
Jul 29, 2024
fdebe36
add Bitmap.Clone overload with RectangleF
Jul 30, 2024
3c8d4db
fix TextureBrush constructors singnatures
Jul 30, 2024
054a330
fix UpdateShader method from TextureBrush, including matrix in the code
Jul 30, 2024
9781a50
fix TextureBrushUnitTest
Jul 30, 2024
6400427
minor change in summary for HatchBrush constructor
Jul 30, 2024
1ab0f61
simplify HatchBrush.UpdateShader method and improve readability
Aug 4, 2024
afa0daa
update hit threshold for image comparison
Aug 4, 2024
04c545d
enhance HashBrush test cases
Aug 4, 2024
4af5eed
update color-green.png expected with #0F0 instead of #008000
Aug 4, 2024
6787b62
fix LinearGradientBrush.UpdateShader method
Aug 4, 2024
17f7511
simplify test cases comparing images and rename expected images with …
Aug 4, 2024
6528e05
add matrix comparison in LinearGradientBrush unit test for Clone method
Aug 5, 2024
403c2b7
fix GraphicsPath.Clone method
Aug 6, 2024
9c5c2a4
fix GraphicsPath.GetBounds method
Aug 6, 2024
aac7c10
fix GraphicsPath.CreatePath method when bezier curve has odd points c…
Aug 6, 2024
8754213
fix PathGradientBrush.InterpolationColors property set
Aug 6, 2024
3a0d609
fix GraphicsPath.Clone method
Aug 6, 2024
d3435c9
generalize Brush's SetBlendTriangularShape and SetSigmaBellShape methods
Aug 6, 2024
84e06c5
fix PathGradientBrush.Clone method
Aug 6, 2024
75b7b46
fix PathGradientBrush.InterpolationColors property
Aug 6, 2024
3c5706e
fix PathGradientBrush.UpdateShader method and constructor
Aug 6, 2024
c622ae3
fix LinearGradientBrush.UpdateShader method
Aug 6, 2024
e6eadcc
add missing PathGradientBrush constructors
Aug 6, 2024
19c45d1
rename m_interpolation by m_color in PathGradientBrush class
Aug 6, 2024
ffca01c
make m_color and m_surround independent colors and define center by u…
Aug 6, 2024
ac5dfab
add GraphicsPath.FromSvg extra method
Aug 6, 2024
3578972
add .DS_Store to gitignore
Aug 6, 2024
2340f3c
fix GraphicsPath.AddString method when StringFormatFlags.NoClip is no…
Aug 7, 2024
d768f35
fix initial center calculation in PathGradientBrush class
Aug 7, 2024
d46cff8
implement circle vs ellipsis in PathGradientBrush class and fix radiu…
Aug 7, 2024
84b8f25
fix PathGradientBrush.CreatePath method to create a closed shape
Aug 7, 2024
abedc21
fix PathGradientBrush.UpdateShader method to consider ellipse gradient
Aug 7, 2024
9c6d7c4
close open figures in GraphicsPath class
Aug 8, 2024
e509af9
minor change in GraphicsPathUnitTest for simplicity
Aug 8, 2024
cd2f44e
minor typo fix in comment
Aug 15, 2024
89e969f
adjust image similarity threshold in unit-tests because of antialiasing
Aug 15, 2024
954da92
compare images by pixel color euclidean distance, add bounding rectan…
Aug 16, 2024
0691c88
fix PathGradientBrush.UpdateShader without transforming center/focus …
Aug 16, 2024
1b4580b
fix PathGradientBrush.UpdateShader translation based on center point
Aug 16, 2024
ef797a9
fix infinite recursion in Region.IsVisible method
Aug 19, 2024
97cb016
redefine Ceiling, Trunkcate and Round from PointF struct in Point struct
Aug 19, 2024
50de470
fix Region.IsVisible based on Point.Truncate method
Aug 19, 2024
62974f5
add Vector2 related methods to PointF struct
Aug 19, 2024
ac1c398
update unit tests for Point and PointF after migrating Ceiling, Round…
Aug 19, 2024
d455619
add unit tests for Vector2 related methods in PointF struct
Aug 19, 2024
ccb44d2
fix possible null Matrix parameter value in GraphicsPath.Flatten method
Aug 20, 2024
c6a6c31
fix Clone method in LinearGradientBrush and PathGradientBrush classes
Aug 21, 2024
0579daa
minor change
Aug 21, 2024
3ddef77
minor identation change in Region class
Aug 22, 2024
fa8747f
fix PathGradientBrush.CenterColor default depending if SurroundColors…
Aug 23, 2024
b3a3a65
add constraint check in PathGradientBrush.SurroundColors property set
Aug 23, 2024
9f3535f
add support for custom shape gradient in PathGradientBrush extending …
Aug 23, 2024
71cd795
rename m_blend property by m_factor in LinearGradientBrush and PathGr…
Aug 23, 2024
b2f6c9e
add Color.Blend method for mixing two colors
Aug 23, 2024
98a454e
fix GraphicsPath.IsVisible method due to behavior differences with Skia
Aug 23, 2024
a09937e
simplify test utils module's methods: GetCenterPoint and GetBoundingR…
Aug 23, 2024
f3a8787
change offset of GraphicsPath.IsVisible method because skia is not co…
Aug 23, 2024
40fb959
minor fix in ComputeColor.PathGradientBrush when calculate distances …
Aug 23, 2024
e433d31
add PathGradientBrush unit tests
Aug 23, 2024
0083160
Merge https://github.com/genexuslabs/GeneXus.Drawing-DotNet into feat…
Aug 26, 2024
b40d284
update README with new components
Aug 26, 2024
e73fe86
remove unnecesary whitespaces in PathGradientBrush class
Aug 27, 2024
3b96de8
remove ApplyFactor method and fix how colors are calculated based on …
Aug 30, 2024
b2aba42
fix PathGradientBrush.UpdateShader when just using blend factors
Aug 30, 2024
39e70d0
add basic test case for PathGradientBrush.Transform property
Aug 30, 2024
546612e
define PathGradientBrush helper methods as private: Intersect and Tri…
Sep 2, 2024
3ff375d
apply clamp in PathGradientBrush helper method: Project
Sep 2, 2024
2859456
add support for PathGradientBrush.FocusScale property
Sep 2, 2024
bca0277
add comments on PathGradientBrush helper methods
Sep 3, 2024
e1010dd
fix PathGradientBrush when ScaleFactor is zero (default value) and im…
Sep 3, 2024
97d11df
add FocusScales test-cases for PathGradientBrush
Sep 3, 2024
27fca8f
minor change for improving readability
Sep 4, 2024
d44ff7c
implement Graphics' Restore and Save methods, add GraphicsState class
Sep 4, 2024
cd02f2b
remove unused SKCanvas reference from GraphicsState class
Sep 4, 2024
145196d
fix several indentation issues with spaces
Sep 5, 2024
54d50e8
fix Graphics.Transform property
Sep 6, 2024
b50c7f7
fix Graphics.Save method to use SKCanvas.Save method instead of SKCan…
Sep 6, 2024
a4ab4c6
fix Graphics.DrawCurve, Graphics.DrawClosedCurve and Graphics.FillClo…
Sep 6, 2024
90ffc2b
fix mutually infinite recursion in Graphics.IsVisible overloads
Sep 6, 2024
4e8996b
fix Graphics.DrawImage method over rectangles
Sep 6, 2024
4574ff2
fix Graphics.DrawImage method over custom shape
Sep 6, 2024
b6c56ae
add support for DigitSubstitutionMethod and DigitSubstitutionLanguage…
Sep 6, 2024
a8fe2e0
fix Graphics' clip methods
Sep 8, 2024
8c93e08
fix Graphics.VisibleClipBounds definition (getter only)
Sep 8, 2024
bb5448c
minor change in method description
Sep 8, 2024
1057bb7
fix Grapchis.RotateTransform method angle
Sep 8, 2024
123d1f3
fix Graphics.MultiplyTransform method
Sep 8, 2024
d406633
uniformize the way of getting DPI value in Graphics and update Font t…
Sep 9, 2024
d66b2a2
minor changes
Sep 9, 2024
eb03287
Merge branch 'main' of https://github.com/genexuslabs/GeneXus.Drawing…
Sep 9, 2024
d06caf4
fix GraphicsPath.AddBeziers method
Sep 9, 2024
58d7490
change GraphicsPath constructor visibility to internal
Sep 9, 2024
174899a
improve Graphics.DrawImage for maintainability
Sep 9, 2024
82be880
fix missin gusing in Graphics.MeasureStringInternal method
Sep 9, 2024
b9acac7
fix GraphicsPath.AddLines method
Sep 9, 2024
bb8165e
implement Graphics.TransformPoints method with CoordinateSpace parame…
Sep 9, 2024
8ac2b48
add message to exceptions that not have one
Sep 10, 2024
facf33a
fix Graphics.GetNearestColor method
Sep 10, 2024
23e5a2b
fix Graphics.BeginContainer method
Sep 10, 2024
1c66a1a
add Graphics.GetContextInfo missing method
Sep 10, 2024
d062792
fix typo in RegionUnitTest
Sep 10, 2024
d3d50cf
change Region constructor visiblity and fix MakeInfinite method
Sep 10, 2024
d644003
fix Graphics.Clip property
Sep 10, 2024
2f4e848
change every Graphics draw/fill method to use path for implementing I…
Sep 10, 2024
80c284e
fix GraphicsPath.IsVisible method that must check if point/rect is co…
Sep 10, 2024
31e5870
fix Graphics' BeginContainer that must reset the class state until to…
Sep 10, 2024
67b989d
add support for Graphics.CompositingMode
Sep 10, 2024
ba3f202
fix HatchBrush shader rendering
Sep 11, 2024
4f9f873
add support for Graphics.RenderingOrigin property
Sep 11, 2024
8b05c2d
fix CompositingMode enum name
Sep 11, 2024
3484543
add support for Graphics.InterpolationMode property
Sep 11, 2024
f4c453e
fix StringFormat.GenericTypographic property default flags
Sep 13, 2024
4ef1f64
fix StringFormat border case when applying wrapping and avoid subpixe…
Sep 13, 2024
4900040
fix Graphics.MeasureCharacterRanges method in order to consider Measu…
Sep 13, 2024
1a145ea
fix Graphics.DrawString overloads calls
Sep 13, 2024
763d0ba
fix Graphics.MeasureString overload calls
Sep 13, 2024
dc374ee
add support for Graphics.SmoothingMode property
Sep 13, 2024
b46fd46
fix GraphicsPath.AddString overload calls
Sep 13, 2024
64e1455
fix and improve readability of AddString internal method that applies…
Sep 13, 2024
99baf27
fix Graphics.MeasureStringInternal method that's not considering tota…
Sep 13, 2024
1cf5bd3
fix Gracphis.IsVisible disposable reference by making a copy
Sep 13, 2024
d1ccf87
consider font Unit in Graphics' DrawString, MeasureCharacterRanges an…
Sep 13, 2024
96c7545
fix lineHeight calculation in GraphicsPath.AddString method
Sep 13, 2024
970c794
add ColorTranslator class
Sep 16, 2024
4fe30e9
fix Color class for known colors by setting the name and index
Sep 16, 2024
e8a9c9e
minor fix in description of ColorTranslator class
Sep 16, 2024
a1da166
add ConvertFromString method in ColorTranslator class
Sep 16, 2024
8324182
add ColorConverter class
Sep 16, 2024
d742aa3
update ColorTranslator unit test after fixing known colors for Color …
Sep 16, 2024
e4b1b38
add summary for ColorConverter class and update README
Sep 16, 2024
b54e031
fix AddString typeface disposed variable
Sep 16, 2024
e8649b7
minor change
Sep 16, 2024
7238c05
add note for Graphics.DrawString method that uses path drawing instea…
Sep 16, 2024
e76ef8b
add Graphics.GetStringBounds private method to be used by MeasureChar…
Sep 16, 2024
9558d90
add ceiling in GraphicsPath.AddString method in order to skia can ren…
Sep 16, 2024
66dbf9e
minor change in StringFormat.ApplyWrapping and StringFormat.ApplyTrim…
Sep 16, 2024
6640856
add CompareImage to Utils class for comparing images
Sep 16, 2024
ac9bbfc
add notes in Graphics class for PixelOffsetMode, TextContrast and Tex…
Sep 16, 2024
9904c00
add unit tests for Graphics class
Sep 16, 2024
d59937b
Merge https://github.com/genexuslabs/GeneXus.Drawing-DotNet into feat…
Sep 16, 2024
6c89811
add SolidBrush to README
Sep 16, 2024
e680b2c
add StringFormat to README
Sep 16, 2024
941db7b
adjust thresholds for DrawString, MeasureString and MeasureCharacterR…
Sep 16, 2024
a94ebf4
remove ceiling defining the underline when adding string to GraphicsPath
Sep 20, 2024
0b97118
Change properties A, R, G, and B from int to the expected byte type f…
claudiamurialdo Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ bin/
obj/
/_packages
GeneXus.Drawing-DotNet.sln.DotSettings.user
/Test/Common/res/images/.out
.DS_Store
95 changes: 72 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ This repository is organized as follows:
Root
├─ src : source code
│ ├─ Common
│ │ ├─ Drawing2D : elements for GeneXus.Drawing.Drawing2D
│ │ │ └─ ...
│ │ ├─ Imaging : elements for GeneXus.Drawing.Imaging
│ │ │ └─ ...
│ │ ├─ Interop : elements for GeneXus.Drawing.Interop
Expand All @@ -46,10 +48,12 @@ Root
│ │ │ └─ ...
│ │ └─ ... : elements for GeneXus.Drawing
│ │
│ └─ PackageREADME.md
│ └─ PackageREADME.md : package readme file
├─ test : unit tests
│ ├─ Common
│ │ ├─ Drawing2D : unit-tests for GeneXus.Drawing.Drawing2D
│ │ │ └─ ...
│ │ ├─ Text : unit-tests for GeneXus.Drawing.Text
│ │ │ └─ ...
│ │ └─ ... : unit-tests for GeneXus.Drawing
Expand All @@ -75,28 +79,71 @@ This section describes each module (namespace) specifiying which elements are pa
### GeneXus.Drawing.Common
Basic graphics funcionalities based on `System.Drawing`.

| Name | Type | Description
|----------------------|----------|--------------
| `Bitmap` | Class | Represents an image defined by pixels.
| `Color` | Class | Defines colors used for drawing.
| `Font` | Class | Defines a format for text, including font family, size, and style.
| `Icon` | Class | Represents an icon image.
| `Image` | Class | Represents an image in a specific format.
| `Svg` <sup>(1)</sup> | Class | Represents Scalable Vector Graphics.
| `Point` | Struct | Defines an x and y coordinate in a 2D plane.
| `PointF` | Struct | Defines a floating-point x and y coordinate in a 2D plane.
| `Rectangle` | Struct | Defines an x, y, width, and height of a rectangle.
| `RectangleF` | Struct | Defines a floating-point x, y, width, and height of a rectangle.
| `Size` | Struct | Defines the width and height of a rectangular area.
| `SizeF` | Struct | Defines the width and height of a rectangular area with floating-point values.
| `FontSlant` | Enum | Specifies the slant of a font.
| `FontStyle` | Enum | Specifies the style of a font.
| `GraphicsUnit` | Enum | Specifies the unit of measure for drawing operations.
| `KnownColor` | Enum | Defines predefined colors.
| `RotateFlipType` | Enum | Specifies how an image is rotated or flipped.
| Name | Type | Description
|-------------------------|----------|--------------
| `Bitmap` | Class | Represents an image defined by pixels.
| `Brush` | Class | Abstract class for brushes used to fill graphics shapes.
| `Color` | Class | Defines colors used for drawing.
| `ColorConverter` | Class | Converts colors from one data type to another
| `ColorTranslator` | Class | Translates colors to and from HTML, OLE and Win32 representations.
| `Font` | Class | Defines a format for text, including font family, size, and style.
| `Graphics` | Class | Provides methods for drawing on a drawing surface.
| `Icon` | Class | Represents an icon image.
| `Image` | Class | Represents an image in a specific format.
| `Pen` | Class | Defines an object used to draw lines and curves.
| `Region` | Class | Defines the area of a drawing surface.
| `SolidBrush` | Class | Defines a brush of a single color.
| `StringFormat` | Class | Defines text layout information, display manipulation and font features.
| `Svg` <sup>(1)</sup> | Class | Represents Scalable Vector Graphics.
| `TextureBrush` | Class | Defines a brush that uses an image to fill shapes.
| `Point` | Struct | Defines an x and y coordinate in a 2D plane.
| `PointF` | Struct | Defines a floating-point x and y coordinate in a 2D plane.
| `Rectangle` | Struct | Defines an x, y, width, and height of a rectangle.
| `RectangleF` | Struct | Defines a floating-point x, y, width, and height of a rectangle.
| `Size` | Struct | Defines the width and height of a rectangular area.
| `SizeF` | Struct | Defines the width and height of a rectangular area with floating-point values.
| `CopyPixelOperation` | Enum | Specifies the type of pixel copying operation.
| `FontSlant` | Enum | Specifies the slant of a font.
| `FontStyle` | Enum | Specifies the style of a font.
| `GraphicsUnit` | Enum | Specifies the unit of measure for drawing operations.
| `KnownColor` | Enum | Defines predefined colors.
| `RotateFlipType` | Enum | Specifies how an image is rotated or flipped.
| `StringAlignment` | Enum | Specifies the alignment of text within a string.
| `StringDigitSubstitute` | Enum | Specifies how digits are substituted in a string.
| `StringFormatFlags` | Enum | Specifies formatting options for strings.
| `StringTrimming` | Enum | Specifies how text is trimmed when it does not fit.

<small><sup>(1)</sup> New element (does not belogs to `System.Drawing` library).</small>

### GeneXus.Drawing.Drawing2D
Advanced 2D graphics functionalities based on `System.Drawing.Drawing2D` for complex vector graphics and rendering tasks.

| Name | Type | Description
|-----------------------|----------|--------------
| `Blend` | Class | Defines a blend of colors along a gradient.
| `ColorBlend` | Class | Defines a blend of colors for a gradient.
| `GraphicsPath` | Class | Represents a series of connected lines and curves.
| `HatchBrush` | Class | Defines a brush with a hatching pattern.
| `PathGradientBrush` | Class | Defines a brush that fills an area with a gradient of colors.
| `LinearGradientBrush` | Class | Defines a brush that fills an area with a linear gradient of colors.
| `Matrix` | Struct | Defines a transformation matrix for graphics operations.
| `PathData` | Struct | Contains data associated with a GraphicsPath object.
| `CombineMode` | Enum | Specifies how two graphics objects are combined.
| `CompositingQuality` | Enum | Specifies the quality of compositing operations.
| `CoordinateSpace` | Enum | Specifies the coordinate space for transformations.
| `DashCap` | Enum | Specifies the cap style for dashed lines.
| `FillMode` | Enum | Specifies the fill mode for filling shapes.
| `InterpolationMode` | Enum | Specifies the interpolation mode for scaling and resizing.
| `LineCap` | Enum | Specifies the shape of the end of a line.
| `LineJoin` | Enum | Specifies the shape used to join two connected lines.
| `MatrixOrder` | Enum | Specifies the order of matrix transformations.
| `PenAlignment` | Enum | Specifies the alignment of a pen's stroke.
| `PenType` | Enum | Specifies the type of pen used for drawing.
| `PixelOffsetMode` | Enum | Specifies how to offset pixels when drawing.
| `SmoothingMode` | Enum | Specifies the level of smoothing applied to graphics.
| `WarpMode` | Enum | Specifies how text is warped.
| `WrapMode` | Enum | Specifies how text wraps within its container.

### GeneXus.Drawing.Imaging
Advanced image processing based on `System.Drawing.Imaging` to support sophisticated image manipulation and format handling.

Expand All @@ -114,9 +161,11 @@ Advanced typographic features based on `System.Drawing.Text` for managing and re
| Name | Type | Description
|---------------------------|----------|--------------
| `FontCollection` | Class | Represents a collection of fonts.
| `InstalledFontCollection` | Class | Represents a collection of installed fonts.
| `PrivateFontCollection` | Class | Represents a collection of private fonts.
| `GenericFontFamilies` | Enum | Specifies generic font families.
| `InstalledFontCollection` | Class | Represents a collection of installed fonts.
| `PrivateFontCollection` | Class | Represents a collection of private fonts.
| `GenericFontFamilies` | Enum | Specifies generic font families.
| `HotkeyPrefix` | Enum | Specifies how hotkey prefixes are rendered.
| `TextRenderingHint` | Enum | Specifies the level of text rendering quality.

### GeneXus.Drawing.Interop
Advanced interoperability utilities based on `System.Drawing.Interop` that includes definitions used in font management and graphics rendering.
Expand Down
19 changes: 15 additions & 4 deletions src/Common/Bitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ public Bitmap(float width, float height)
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified size
/// and with the resolution of the specified <see cref='Graphics'/> object.
/// </summary>
//public Bitmap(int width, int height, object g) // TODO: Implement Graphics
// : this(width, height) => throw new NotImplementedException();
public Bitmap(int width, int height, Graphics g)
: this(width, height)
{
HorizontalResolution = g.DpiX;
VerticalResolution = g.DpiY;
}

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified size and format.
Expand Down Expand Up @@ -119,13 +123,20 @@ public Bitmap(Image original, Size size)
/// Creates a copy of the section of this <see cref='Bitmap'/> defined
/// by <see cref='Rectangle'/> structure and with a specified PixelFormat enumeration.
/// </summary>
public object Clone(Rectangle rect, PixelFormat format)
public object Clone(RectangleF rect, PixelFormat format)
{
var bitmap = new Bitmap(rect.Width, rect.Height);
var portion = SKRectI.Truncate(rect.m_rect);
return m_bitmap.ExtractSubset(bitmap.m_bitmap, portion) ? bitmap : Clone();
}

/// <summary>
/// Creates a copy of the section of this <see cref='Bitmap'/> defined
/// by <see cref='Rectangle'/> structure and with a specified PixelFormat enumeration.
/// </summary>
public object Clone(Rectangle rect, PixelFormat format)
=> Clone(new RectangleF(rect.m_rect), format);

#endregion


Expand Down Expand Up @@ -253,7 +264,7 @@ protected override void RotateFlip(int degrees, float scaleX, float scaleY)
/// </summary>
public void SetPixel(int x, int y, Color color)
{
var c = new SKColor((byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
var c = new SKColor(color.R, color.G, color.B, color.A);
m_bitmap.SetPixel(x, y, c);
}

Expand Down
192 changes: 192 additions & 0 deletions src/Common/Brush.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
using System;
using SkiaSharp;

namespace GeneXus.Drawing;

public abstract class Brush : IDisposable, ICloneable
{
internal readonly SKPaint m_paint;

internal Brush(SKPaint paint)
{
m_paint = paint ?? throw new ArgumentNullException(nameof(paint));
m_paint.Style = SKPaintStyle.Fill;
}

/// <summary>
/// Cleans up resources for this <see cref='Brush'/>.
/// </summary>
~Brush() => Dispose(false);


#region IDisposable

/// <summary>
/// Cleans up resources for this <see cref='Brush'/>.
/// </summary>
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}

protected virtual void Dispose(bool disposing) => m_paint.Dispose();

#endregion


#region IClonable

/// <summary>
/// Creates an exact copy of this <see cref='Pen'/>.
/// </summary>
public abstract object Clone();

#endregion


#region Operators

/// <summary>
/// Creates a <see cref='SKPaint'/> with the coordinates of the specified <see cref='Brush'/>.
/// </summary>
public static explicit operator SKPaint(Brush brush) => brush.m_paint;

#endregion


#region Utilities

protected static Drawing2D.Blend GetBlendTriangularShape(float focus, float scale)
{
if (focus < 0 || focus > 1)
throw new ArgumentException("Invalid focus value", nameof(focus));
if (scale < 0 || scale > 1)
throw new ArgumentException("Invalid scale value", nameof(scale));

int count = focus == 0 || focus == 1 ? 2 : 3;
Drawing2D.Blend blend = new(count);

if (focus == 0)
{
blend.Positions[0] = 0;
blend.Factors[1] = scale;
blend.Positions[1] = 1;
blend.Factors[1] = 0;
}
else if (focus == 1)
{
blend.Positions[0] = 0;
blend.Factors[1] = 0;
blend.Positions[1] = 1;
blend.Factors[1] = scale;
}
else
{
blend.Positions[0] = 0;
blend.Factors[0] = 0;
blend.Positions[1] = focus;
blend.Factors[1] = scale;
blend.Positions[2] = 1;
blend.Factors[2] = 0;
}
return blend;
}

protected static Drawing2D.Blend GetSigmaBellShape(float focus, float scale = 1.0f)
{
if (focus < 0 || focus > 1)
throw new ArgumentException("Invalid focus value", nameof(focus));
if (scale < 0 || scale > 1)
throw new ArgumentException("Invalid scale value", nameof(scale));

int count = focus == 0 || focus == 1 ? 256 : 511;
Drawing2D.Blend m_blend = new(count);

// TODO: clear preset colors

float fallOffLenght = 2.0f;
if (focus == 0)
{
m_blend.Positions[0] = focus;
m_blend.Factors[0] = scale;

SigmaBellBlend(ref m_blend, focus, scale, 1 / fallOffLenght, 1f / 2, 1f / 255, 1, count - 1, true);

m_blend.Positions[count - 1] = 1f;
m_blend.Factors[count - 1] = 0f;
}
else if (focus == 1)
{
m_blend.Positions[0] = 0f;
m_blend.Factors[0] = 0f;

SigmaBellBlend(ref m_blend, focus, scale, 1 / fallOffLenght, 1f / 2, 1f / 255, 1, count - 1, false);

m_blend.Positions[count - 1] = focus;
m_blend.Factors[count - 1] = scale;
}
else
{
int middle = count / 2;

// left part of the sigma bell
m_blend.Positions[0] = 0f;
m_blend.Factors[0] = 0f;

SigmaBellBlend(ref m_blend, focus, scale, focus / (2 * fallOffLenght), focus / 2, focus / 255, 1, middle, false);

// middle part of the sigma bell
m_blend.Positions[middle] = focus;
m_blend.Factors[middle] = scale;

// right part of the sigma bell
SigmaBellBlend(ref m_blend, focus, scale, (1 - focus) / (2 * fallOffLenght), (1 + focus) / 2, (1 - focus) / 255, middle + 1, count - 1, true);

m_blend.Positions[count - 1] = 1f;
m_blend.Factors[count - 1] = 0f;
}
return m_blend;

static void SigmaBellBlend(ref Drawing2D.Blend blend, float focus, float scale, float sigma, float mean, float delta, int startIndex, int endIndex, bool invert)
{
float sg = invert ? -1 : 1;
float x0 = invert ? 1f : 0f;

float cb = (1 + sg * Erf(x0, sigma, mean)) / 2;
float ct = (1 + sg * Erf(focus, sigma, mean)) / 2;
float ch = ct - cb;

float offset = invert ? focus : 0;
float pos = delta + offset;

for (int index = startIndex; index < endIndex; index++, pos += delta)
{
blend.Positions[index] = pos;
blend.Factors[index] = scale / ch * ((1 + sg * Erf(pos, sigma, mean)) / 2 - cb);
}
}

static float Erf(float x, float sigma, float mean, int terms = 6)
{
/*
* Error function (Erf) for Gaussian distribution by Maclaurin series:
* erf (z) = (2 / sqrt (pi)) * infinite sum of [(pow (-1, n) * pow (z, 2n+1))/(n! * (2n+1))]
*/
float constant = 2 / (float)Math.Sqrt(Math.PI);
float z = (x - mean) / (sigma * (float)Math.Sqrt(2));

float series = z;
for (int n = 1, fact = 1; n < terms; n++, fact *= n)
{
int sign = (int)Math.Pow(-1, n);
int step = 2 * n + 1;
series += sign * (float)Math.Pow(z, step) / (fact * step);
}

return constant * series;
}
}

#endregion
}
Loading
Loading