5using System.Threading.Tasks;
20 public static readonly
string[] SvgContentTypes =
new string[] { ImageCodec.ContentTypeSvg };
21 public static readonly
string[] SvgFileExtensions =
new string[] { ImageCodec.FileExtensionSvg };
36 public Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding,
37 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
43 using (MemoryStream ms =
new MemoryStream(Data))
60 if (Object is
string s && s.IndexOf(
"<svg", StringComparison.OrdinalIgnoreCase) >= 0)
65 else if (Object is SKSvg)
75 public Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding,
ICodecProgress Progress, params
string[] AcceptedContentTypes)
78 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"Unable to encode object, or content type not accepted.", nameof(Object))));
80 if (!(Object is
string Xml))
81 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"Encoder expects raw SVG markup string.", nameof(Object))));
83 if (Xml.IndexOf(
"<svg", StringComparison.OrdinalIgnoreCase) < 0)
84 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"Object does not appear to be valid SVG markup.", nameof(Object))));
88 ContentType +=
"; charset=utf-8";
89 Encoding = Encoding.UTF8;
92 ContentType +=
"; charset=" + Encoding.WebName;
94 return Task.FromResult(
new ContentResponse(ContentType, Object, Encoding.GetBytes(Xml)));
99 if (
string.Equals(FileExtension,
"svg", StringComparison.OrdinalIgnoreCase))
105 ContentType =
string.Empty;
113 FileExtension =
"svg";
117 FileExtension =
string.Empty;
SVG image encoder/decoder. Decodes to an SKSvg.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
string[] FileExtensions
Supported file extensions.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
string[] ContentTypes
Supported content types.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
Contains information about a response to a content request.
const string ContentTypeSvg
image/svg+xml
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...