image-in-browser
Version:
Package for encoding / decoding images, transforming images, applying filters, drawing primitives on images on the client side (no need for server Node.js)
48 lines • 1.38 kB
JavaScript
import { StringUtils } from '../../common/string-utils.js';
import { IfdValue } from './ifd-value.js';
import { IfdValueType } from '../ifd-value-type.js';
export class IfdAsciiValue extends IfdValue {
get type() {
return IfdValueType.ascii;
}
get length() {
const codeUnits = StringUtils.getCodePoints(this._value);
return codeUnits.length + 1;
}
constructor(value) {
super();
if (typeof value === 'string') {
this._value = value;
}
else {
this._value = String.fromCodePoint(...value);
}
}
static data(data, length) {
const value = length > 0 ? data.readString(length - 1) : '';
return new IfdAsciiValue(value);
}
toData() {
return StringUtils.getCodePoints(this._value);
}
write(out) {
const bytes = StringUtils.getCodePoints(this._value);
out.writeBytes(bytes);
out.writeByte(0);
}
setString(v) {
this._value = v;
}
equals(other) {
return (other instanceof IfdAsciiValue &&
this.length === other.length &&
this._value === this._value);
}
clone() {
return new IfdAsciiValue(this._value);
}
toString() {
return `${this.constructor.name} (${this._value})`;
}
}
//# sourceMappingURL=ifd-ascii-value.js.map