#756 Adding alt text feature
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { uniqueId } from "@util/convenience-functions";
|
||||
|
||||
import { IContext, IXmlableObject } from "@file/xml-components";
|
||||
import { DocPropertiesOptions } from "@file/drawing/doc-properties/doc-properties";
|
||||
|
||||
import { Drawing, IFloating } from "../../drawing";
|
||||
import { IMediaTransformation } from "../../media";
|
||||
@ -11,6 +12,7 @@ export interface IImageOptions {
|
||||
readonly data: Buffer | string | Uint8Array | ArrayBuffer;
|
||||
readonly transformation: IMediaTransformation;
|
||||
readonly floating?: IFloating;
|
||||
readonly altText?: DocPropertiesOptions;
|
||||
}
|
||||
|
||||
export class ImageRun extends Run {
|
||||
@ -37,7 +39,7 @@ export class ImageRun extends Run {
|
||||
rotation: options.transformation.rotation ? options.transformation.rotation * 60000 : undefined,
|
||||
},
|
||||
};
|
||||
const drawing = new Drawing(this.imageData, { floating: options.floating });
|
||||
const drawing = new Drawing(this.imageData, { floating: options.floating, docProperties: options.altText });
|
||||
|
||||
this.root.push(drawing);
|
||||
}
|
||||
@ -49,15 +51,16 @@ export class ImageRun extends Run {
|
||||
}
|
||||
|
||||
private convertDataURIToBinary(dataURI: string): Uint8Array {
|
||||
// https://gist.github.com/borismus/1032746
|
||||
// https://github.com/mafintosh/base64-to-uint8array
|
||||
const BASE64_MARKER = ";base64,";
|
||||
|
||||
const base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
|
||||
|
||||
if (typeof atob === "function") {
|
||||
// https://gist.github.com/borismus/1032746
|
||||
// https://github.com/mafintosh/base64-to-uint8array
|
||||
const BASE64_MARKER = ";base64,";
|
||||
const base64Index = dataURI.indexOf(BASE64_MARKER);
|
||||
|
||||
const base64IndexWithOffset = base64Index === -1 ? 0 : base64Index + BASE64_MARKER.length;
|
||||
|
||||
return new Uint8Array(
|
||||
atob(dataURI.substring(base64Index))
|
||||
atob(dataURI.substring(base64IndexWithOffset))
|
||||
.split("")
|
||||
.map((c) => c.charCodeAt(0)),
|
||||
);
|
||||
|
Reference in New Issue
Block a user