pdf-lib
Version:
Library for creating and modifying PDF files in JavaScript
43 lines (42 loc) • 2.05 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/* eslint-disable new-cap */
import isString from 'lodash/isString';
import { PDFName } from '../../../pdf-objects';
import PDFOperator from '../../../pdf-operators/PDFOperator';
import { addStringToBuffer, or } from '../../../../utils';
import { isInstance, isNumber, validate } from '../../../../utils/validate';
/**
* Set the text font, Tf, to font and the text font size, Tfs, to size. font shall
* be the name of a font resource in the Font subdictionary of the current resource
* dictionary; size shall be a number representing a scale factor. There is no
* initial value for either font or size; they shall be specified explicitly by
* using Tf before any text is shown.
*/
var Tf = /** @class */ (function (_super) {
__extends(Tf, _super);
function Tf(font, size) {
var _this = _super.call(this) || this;
_this.toString = function () { return _this.font + " " + _this.size + " Tf\n"; };
_this.bytesSize = function () { return _this.toString().length; };
_this.copyBytesInto = function (buffer) {
return addStringToBuffer(_this.toString(), buffer);
};
validate(font, or(isString, isInstance(PDFName)), 'Tf operator arg "font" must be a string or PDFName.');
validate(size, isNumber, 'Tf operator arg "size" must be a number.');
_this.font = isString(font) ? PDFName.from(font) : font;
_this.size = size;
return _this;
}
Tf.of = function (font, size) { return new Tf(font, size); };
return Tf;
}(PDFOperator));
export default Tf;