public class SvgOptions extends ImageOptionsBase implements ITextAsShapesOptions
The SVG file format creation options.
//Renders loaded file and saves it to SVG
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions();
opt.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
img.Save(outSvg, opt);
}
ImageOptionsBase| Constructor and Description |
|---|
SvgOptions() |
| Modifier and Type | Method and Description |
|---|---|
ISvgResourceKeeperCallback |
getCallback()
Gets or sets the callback that can be used to store image and font binary data as user needs
|
float |
getMinimumAbsoluteNonscaledLinewidth()
Lines with width in pixels less than this will be rescaled if absolute rescaling treshold
|
float |
getMinimumLinewidth()
Minumum width of the line relative to minimum non-rescaled linewidth.
|
float |
getMinimumRelativeLinewidthRatio()
Lines with width less than image's size\minimumRelativeLinewidthRatio will be rescaled if relative rescaling treshold is used.
|
boolean |
getOmitDeclaration()
Whether to omit DOCTYPE declaration - embedded SVG doesn't need it.
|
boolean |
getRescaleSubpixelLinewidths()
Whether sub-pixel linewidths should be rescaled.
|
FileFormat |
getTargetFormat() |
boolean |
getTextAsShapes()
Gets or sets a value indicating whether text must be converted as shapes.
|
boolean |
getUseAbsoluteRescaling()
Wether minimum non-rescaled line widh should be defined relative to whole image size (if false) or in pixels (if true).
|
void |
setCallback(ISvgResourceKeeperCallback value)
Gets or sets the callback that can be used to store image and font binary data as user needs
|
void |
setMinimumAbsoluteNonscaledLinewidth(float value)
Lines with width in pixels less than this will be rescaled if absolute rescaling treshold
|
void |
setMinimumLinewidth(float value)
Minumum width of the line relative to minimum non-rescaled linewidth.
|
void |
setMinimumRelativeLinewidthRatio(float value)
Lines with width less than image's size\minimumRelativeLinewidthRatio will be rescaled if relative rescaling treshold is used.
|
void |
setOmitDeclaration(boolean value)
Whether to omit DOCTYPE declaration - embedded SVG doesn't need it.
|
void |
setRescaleSubpixelLinewidths(boolean value)
Whether sub-pixel linewidths should be rescaled.
|
void |
setTextAsShapes(boolean value)
Gets or sets a value indicating whether text must be converted as shapes.
|
void |
setUseAbsoluteRescaling(boolean value)
Wether minimum non-rescaled line widh should be defined relative to whole image size (if false) or in pixels (if true).
|
getInterruptionToken, getLayers, getOutputMode, getPalette, getPc3File, getRenderToGraphicsBound, getResolutionSettings, getRotation, getSource, getTimeout, getUserWatermarkColor, getUserWatermarkText, getVectorRasterizationOptions, getXmpData, setInterruptionToken, setLayers, setOutputMode, setPalette, setPc3File, setRenderToGraphicsBound, setResolutionSettings, setRotation, setSource, setTimeout, setUserWatermarkColor, setUserWatermarkText, setVectorRasterizationOptions, setXmpDatapublic final boolean getTextAsShapes()
Gets or sets a value indicating whether text must be converted as shapes. By default text will be converted to shapes, so it won't be selectable.
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions();
opt.TextAsShapes = true;
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
Value:
true if all text should be turned into SVG shapes in the convertion; otherwise, false.getTextAsShapes in interface ITextAsShapesOptionspublic final void setTextAsShapes(boolean value)
Gets or sets a value indicating whether text must be converted as shapes. By default text will be converted to shapes, so it won't be selectable.
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions();
opt.TextAsShapes = true;
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
Value:
true if all text should be turned into SVG shapes in the convertion; otherwise, false.setTextAsShapes in interface ITextAsShapesOptionspublic final ISvgResourceKeeperCallback getCallback()
Gets or sets the callback that can be used to store image and font binary data as user needs
//An example of a simple callback that could only save one font and one image
internal class SvgCallback : ISvgResourceKeeperCallback
{
bool fontStoreExternal;
Stream streamForFont;
string fontFileName;
string imageFileName;
Stream streamForImage;
bool imageStoreExternal;
Stream streamForSvg;
string nameForSvg;
public SvgCallback(bool fontStoreExternal, Stream streamForFont, string fontFileName, string imageFileName, Stream streamForImage, bool imageStoreExternal, Stream streamForSvg, string nameForSvg)
{
this.fontFileName = fontFileName;
this.fontStoreExternal = fontStoreExternal;
this.streamForFont = streamForFont;
this.streamForImage = streamForImage;
this.imageFileName = imageFileName;
this.imageStoreExternal = imageStoreExternal;
this.streamForSvg = streamForSvg;
this.nameForSvg = nameForSvg;
}
public void OnFontResourceReady(FontStoringArgs args)
{
if (!fontStoreExternal)
args.FontStoreType = FontStoreType.Embedded;
else
{
args.FontStoreType = FontStoreType.Stream;
args.FontFileUri = fontFileName;
args.DestFontStream = streamForFont;
args.DisposeStream = true;
}
}
public string OnImageResourceReady(byte[] imageData, SvgImageType imageType, string suggestedFileName, ref bool useEmbeddedImage)
{
if (!imageStoreExternal)
{
useEmbeddedImage = true;
return suggestedFileName;
}
else
{
useEmbeddedImage = false;
if (streamForImage != null)
{
streamForImage.Write(imageData, 0, imageData.Length);
streamForImage.Dispose();
}
return imageFileName;
}
}
public string OnSvgDocumentReady(byte[] htmlData, string suggestedFileName)
{
if (streamForSvg != null)
{
streamForSvg.Write(htmlData, 0, htmlData.Length);
streamForSvg.Dispose();
}
return nameForSvg;
}
}
//using the callback to store rendered SVG
using (Stream content = File.Open(outCallback, FileMode.Create))
{
SvgCallback callback = new SvgCallback(false, null, "font.ttf", "", null, false, content, outCallback);
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions() { TextAsShapes = false };
opt.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
opt.Callback = callback;
img.Save(outFile, opt);
}
}
//using callback to store font
using (Stream font = File.Open(outFont, FileMode.Create))
{
SvgCallback callback = new SvgCallback(true, font, "font.ttf", "", null, false, content, outCallback);
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions() { TextAsShapes = false };
opt.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
opt.Callback = callback;
img.Save(outFile, opt);
}
}
//using callback to store raster content
using (Stream image = File.Open(outRaster, FileMode.Create))
{
SvgCallback callback = new SvgCallback(false, null, "", "raster.png", image, true, content, outCallback);
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions();
opt.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
opt.Callback = callback;
img.Save(outFile, opt);
}
}
Value:
The callbackpublic final void setCallback(ISvgResourceKeeperCallback value)
Gets or sets the callback that can be used to store image and font binary data as user needs
//An example of a simple callback that could only save one font and one image
internal class SvgCallback : ISvgResourceKeeperCallback
{
bool fontStoreExternal;
Stream streamForFont;
string fontFileName;
string imageFileName;
Stream streamForImage;
bool imageStoreExternal;
Stream streamForSvg;
string nameForSvg;
public SvgCallback(bool fontStoreExternal, Stream streamForFont, string fontFileName, string imageFileName, Stream streamForImage, bool imageStoreExternal, Stream streamForSvg, string nameForSvg)
{
this.fontFileName = fontFileName;
this.fontStoreExternal = fontStoreExternal;
this.streamForFont = streamForFont;
this.streamForImage = streamForImage;
this.imageFileName = imageFileName;
this.imageStoreExternal = imageStoreExternal;
this.streamForSvg = streamForSvg;
this.nameForSvg = nameForSvg;
}
public void OnFontResourceReady(FontStoringArgs args)
{
if (!fontStoreExternal)
args.FontStoreType = FontStoreType.Embedded;
else
{
args.FontStoreType = FontStoreType.Stream;
args.FontFileUri = fontFileName;
args.DestFontStream = streamForFont;
args.DisposeStream = true;
}
}
public string OnImageResourceReady(byte[] imageData, SvgImageType imageType, string suggestedFileName, ref bool useEmbeddedImage)
{
if (!imageStoreExternal)
{
useEmbeddedImage = true;
return suggestedFileName;
}
else
{
useEmbeddedImage = false;
if (streamForImage != null)
{
streamForImage.Write(imageData, 0, imageData.Length);
streamForImage.Dispose();
}
return imageFileName;
}
}
public string OnSvgDocumentReady(byte[] htmlData, string suggestedFileName)
{
if (streamForSvg != null)
{
streamForSvg.Write(htmlData, 0, htmlData.Length);
streamForSvg.Dispose();
}
return nameForSvg;
}
}
//using the callback to store rendered SVG
using (Stream content = File.Open(outCallback, FileMode.Create))
{
SvgCallback callback = new SvgCallback(false, null, "font.ttf", "", null, false, content, outCallback);
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions() { TextAsShapes = false };
opt.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
opt.Callback = callback;
img.Save(outFile, opt);
}
}
//using callback to store font
using (Stream font = File.Open(outFont, FileMode.Create))
{
SvgCallback callback = new SvgCallback(true, font, "font.ttf", "", null, false, content, outCallback);
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions() { TextAsShapes = false };
opt.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
opt.Callback = callback;
img.Save(outFile, opt);
}
}
//using callback to store raster content
using (Stream image = File.Open(outRaster, FileMode.Create))
{
SvgCallback callback = new SvgCallback(false, null, "", "raster.png", image, true, content, outCallback);
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions();
opt.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
opt.Callback = callback;
img.Save(outFile, opt);
}
}
Value:
The callbackpublic final boolean getRescaleSubpixelLinewidths()
Whether sub-pixel linewidths should be rescaled. If set to true, lines thinner than a width specified by other options will be drawn thicker, asymptotically approaching the minimum width
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions();
opt.RescaleSubpixelLinewidths = false; //now lines with width in source file == 0 will not be visible
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
public final void setRescaleSubpixelLinewidths(boolean value)
Whether sub-pixel linewidths should be rescaled. If set to true, lines thinner than a width specified by other options will be drawn thicker, asymptotically approaching the minimum width
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
SvgOptions opt = new SvgOptions();
opt.RescaleSubpixelLinewidths = false; //now lines with width in source file == 0 will not be visible
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
public final boolean getUseAbsoluteRescaling()
Wether minimum non-rescaled line widh should be defined relative to whole image size (if false) or in pixels (if true). If false, use (/) to specify maximum rate of image size to line width when line won't be rescaled up yet. If true, use (/) to specify minimum unscaled width in pixels
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageWidth = 1000;
cadRasterizationOptions.PageHeight = 1000; // as units are not set, the size is in pixels
SvgOptions opt = new SvgOptions();
opt.UseAbsoluteRescaling = false; //using relative rescaling treshold
opt.MinimumRelativeLinewidthRatio = 5000; //As result, lines thinner than 1/5th of a pixel would be made thicker, approaching the thickness of 1/5th of a pixel
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageWidth = 1000;
cadRasterizationOptions.PageHeight = 1000; // as units are not set, the size is in pixels
SvgOptions opt = new SvgOptions();
opt.UseAbsoluteRescaling = true; //using absolute rescaling treshold
opt.MinimumAbsoluteNonscaledLinewidth = 5; //As result, lines thinner than 5 pixels wide would be made thicker, approaching the thickness of 5 pixels
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
public final void setUseAbsoluteRescaling(boolean value)
Wether minimum non-rescaled line widh should be defined relative to whole image size (if false) or in pixels (if true). If false, use (/) to specify maximum rate of image size to line width when line won't be rescaled up yet. If true, use (/) to specify minimum unscaled width in pixels
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageWidth = 1000;
cadRasterizationOptions.PageHeight = 1000; // as units are not set, the size is in pixels
SvgOptions opt = new SvgOptions();
opt.UseAbsoluteRescaling = false; //using relative rescaling treshold
opt.MinimumRelativeLinewidthRatio = 5000; //As result, lines thinner than 1/5th of a pixel would be made thicker, approaching the thickness of 1/5th of a pixel
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageWidth = 1000;
cadRasterizationOptions.PageHeight = 1000; // as units are not set, the size is in pixels
SvgOptions opt = new SvgOptions();
opt.UseAbsoluteRescaling = true; //using absolute rescaling treshold
opt.MinimumAbsoluteNonscaledLinewidth = 5; //As result, lines thinner than 5 pixels wide would be made thicker, approaching the thickness of 5 pixels
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
public final float getMinimumRelativeLinewidthRatio()
Lines with width less than image's size\minimumRelativeLinewidthRatio will be rescaled if relative rescaling treshold is used. A smaller dimension is picked as image size.
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageWidth = 1000;
cadRasterizationOptions.PageHeight = 1000; // as units are not set, the size is in pixels
SvgOptions opt = new SvgOptions();
opt.UseAbsoluteRescaling = false; //using relative rescaling limit
opt.MinimumRelativeLinewidthRatio = 5000; //As result, lines thinner than 1/5th of a pixel would be made thicker, approaching the thickness of 1/5th of a pixel
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
public final void setMinimumRelativeLinewidthRatio(float value)
Lines with width less than image's size\minimumRelativeLinewidthRatio will be rescaled if relative rescaling treshold is used. A smaller dimension is picked as image size.
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageWidth = 1000;
cadRasterizationOptions.PageHeight = 1000; // as units are not set, the size is in pixels
SvgOptions opt = new SvgOptions();
opt.UseAbsoluteRescaling = false; //using relative rescaling limit
opt.MinimumRelativeLinewidthRatio = 5000; //As result, lines thinner than 1/5th of a pixel would be made thicker, approaching the thickness of 1/5th of a pixel
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
public final float getMinimumAbsoluteNonscaledLinewidth()
Lines with width in pixels less than this will be rescaled if absolute rescaling treshold
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageWidth = 1000;
cadRasterizationOptions.PageHeight = 1000; // as units are not set, the size is in pixels
SvgOptions opt = new SvgOptions();
opt.UseAbsoluteRescaling = true; //using absolute rescaling limit
opt.MinimumAbsoluteNonscaledLinewidth = 5; //As result, lines thinner than 5 pixels wide would be made thicker, approaching the thickness of 5 pixels
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
public final void setMinimumAbsoluteNonscaledLinewidth(float value)
Lines with width in pixels less than this will be rescaled if absolute rescaling treshold
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageWidth = 1000;
cadRasterizationOptions.PageHeight = 1000; // as units are not set, the size is in pixels
SvgOptions opt = new SvgOptions();
opt.UseAbsoluteRescaling = true; //using absolute rescaling limit
opt.MinimumAbsoluteNonscaledLinewidth = 5; //As result, lines thinner than 5 pixels wide would be made thicker, approaching the thickness of 5 pixels
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
public final float getMinimumLinewidth()
Minumum width of the line relative to minimum non-rescaled linewidth. A line with width of 0 would be drawn with this width if rescaling is used ( as it is by default), lines thicker than that will be drawn thicker until they reach rescaling treshold, lines thicker than that won't be rescaled.
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageWidth = 1000;
cadRasterizationOptions.PageHeight = 1000; // as units are not set, the size is in pixels
SvgOptions opt = new SvgOptions();
opt.UseAbsoluteRescaling = true; //using absolute rescaling limit
opt.MinimumAbsoluteNonscaledLinewidth = 5; //As result, lines thinner than 5 pixels wide would be made thicker, approaching the thickness of 5 pixels
opt.MinimumLinewidth = 0.2f; // As result, lines with width of 0 will be drawn with width of 1 pixel. A line with source width of 1 pixel would be rescaled to be 1.8 pixels wide
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
public final void setMinimumLinewidth(float value)
Minumum width of the line relative to minimum non-rescaled linewidth. A line with width of 0 would be drawn with this width if rescaling is used ( as it is by default), lines thicker than that will be drawn thicker until they reach rescaling treshold, lines thicker than that won't be rescaled.
using (var img = Image.Load(file))
{
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageWidth = 1000;
cadRasterizationOptions.PageHeight = 1000; // as units are not set, the size is in pixels
SvgOptions opt = new SvgOptions();
opt.UseAbsoluteRescaling = true; //using absolute rescaling limit
opt.MinimumAbsoluteNonscaledLinewidth = 5; //As result, lines thinner than 5 pixels wide would be made thicker, approaching the thickness of 5 pixels
opt.MinimumLinewidth = 0.2f; // As result, lines with width of 0 will be drawn with width of 1 pixel. A line with source width of 1 pixel would be rescaled to be 1.8 pixels wide
opt.VectorRasterizationOptions = cadRasterizationOptions;
img.Save(outFile, opt);
}
public final boolean getOmitDeclaration()
Whether to omit DOCTYPE declaration - embedded SVG doesn't need it.
public final void setOmitDeclaration(boolean value)
Whether to omit DOCTYPE declaration - embedded SVG doesn't need it.
public FileFormat getTargetFormat()
getTargetFormat in class ImageOptionsBaseCopyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.