mirror of https://github.com/SixLabors/ImageSharp
7 changed files with 262 additions and 10 deletions
@ -0,0 +1,52 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif |
|||
{ |
|||
public readonly struct EncodedString : IEquatable<EncodedString> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EncodedString" /> struct.
|
|||
/// </summary>
|
|||
/// <param name="text">The text.</param>
|
|||
public EncodedString(string text) |
|||
: this(text, EncodedStringCode.Unicode) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EncodedString" /> struct.
|
|||
/// </summary>
|
|||
/// <param name="text">The text.</param>
|
|||
/// <param name="code">The code.</param>
|
|||
public EncodedString(string text, EncodedStringCode code) |
|||
{ |
|||
this.Text = text; |
|||
this.Code = code; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the text.
|
|||
/// </summary>
|
|||
public string Text { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the character ode.
|
|||
/// </summary>
|
|||
public EncodedStringCode Code { get; } |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) => obj is EncodedString other && this.Equals(other); |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool Equals(EncodedString other) |
|||
{ |
|||
return this.Text == other.Text && this.Code == other.Code; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override string ToString() => this.Text; |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif |
|||
{ |
|||
/// <summary>
|
|||
/// The 8-byte The character code enum.
|
|||
/// </summary>
|
|||
public enum EncodedStringCode |
|||
{ |
|||
/// <summary>
|
|||
/// The ASCII ITU-T T.50 IA5 character code.
|
|||
/// </summary>
|
|||
ASCII, |
|||
|
|||
/// <summary>
|
|||
/// The JIS X208-1990 character code.
|
|||
/// </summary>
|
|||
JIS, |
|||
|
|||
/// <summary>
|
|||
/// The Unicode character code.
|
|||
/// </summary>
|
|||
Unicode, |
|||
|
|||
/// <summary>
|
|||
/// The undefined character code.
|
|||
/// </summary>
|
|||
Undefined |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.Globalization; |
|||
|
|||
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif |
|||
{ |
|||
internal sealed class ExifEncodedString : ExifValue<EncodedString> |
|||
{ |
|||
public ExifEncodedString(ExifTag<EncodedString> tag) |
|||
: base(tag) |
|||
{ |
|||
} |
|||
|
|||
public ExifEncodedString(ExifTagValue tag) |
|||
: base(tag) |
|||
{ |
|||
} |
|||
|
|||
private ExifEncodedString(ExifEncodedString value) |
|||
: base(value) |
|||
{ |
|||
} |
|||
|
|||
public override ExifDataType DataType => ExifDataType.Undefined; |
|||
|
|||
protected override string StringValue => this.Value.Text; |
|||
|
|||
public override bool TrySetValue(object value) |
|||
{ |
|||
if (base.TrySetValue(value)) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
switch (value) |
|||
{ |
|||
case string stringValue: |
|||
this.Value = new EncodedString(stringValue); |
|||
return true; |
|||
default: |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
public override IExifValue DeepClone() => new ExifEncodedString(this); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue