Skip to content

Commit 277c533

Browse files
authored
resolving merge conflicts
1 parent f761680 commit 277c533

File tree

1 file changed

+2
-158
lines changed

1 file changed

+2
-158
lines changed

src/type/p5.Font.js

+2-158
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class Font {
125125
cmdContours[cmdContours.length - 1].push(cmd);
126126
}
127127

128+
return cmdContours.map((commands) => pathToPoints(commands, options, this));
129+
}
128130
/**
129131
*
130132
* Converts text into a 3D model that can be rendered in WebGL mode.
@@ -971,164 +973,6 @@ function font(p5, fn) {
971973

972974
return pfont;
973975
}
974-
975-
async function create(pInst, name, path, descriptors, rawFont) {
976-
977-
let face = createFontFace(name, path, descriptors, rawFont);
978-
979-
// load if we need to
980-
if (face.status !== 'loaded') await face.load();
981-
982-
// add it to the document
983-
document.fonts.add(face);
984-
985-
// return a new p5.Font
986-
return new p5.Font(pInst, face, name, path, rawFont);
987-
}
988-
989-
function unquote(name) {
990-
// Unquote name from CSS
991-
if ((name.startsWith('"') || name.startsWith("'")) && name.at(0) === name.at(-1)) {
992-
return name.slice(1, -1).replace(/\/(['"])/g, '$1');
993-
}
994-
return name;
995-
}
996-
997-
function createFontFace(name, path, descriptors, rawFont) {
998-
999-
if (name.includes(' ')) name = "'" + name + "'"; // NOTE: must be single-quotes
1000-
1001-
let fontArg = rawFont?._data;
1002-
if (!fontArg) {
1003-
if (!validFontTypesRe.test(path)) {
1004-
throw Error(invalidFontError);
1005-
}
1006-
if (!path.startsWith('url(')) {
1007-
path = 'url(' + path + ')';
1008-
}
1009-
fontArg = path;
1010-
}
1011-
1012-
// create/return the FontFace object
1013-
let face = new FontFace(name, fontArg, descriptors);
1014-
if (face.status === 'error') {
1015-
throw Error('Failed to create FontFace for "' + name + '"');
1016-
}
1017-
return face;
1018-
}
1019-
1020-
function extractFontName(font, path) {
1021-
let result, meta = font?.name;
1022-
1023-
// use the metadata if we have it
1024-
if (meta) {
1025-
if (meta.fullName) {
1026-
return meta.fullName;
1027-
}
1028-
if (meta.familyName) {
1029-
result = meta.familyName;
1030-
}
1031-
}
1032-
1033-
if (!result) {
1034-
1035-
// if not, try to extract the name from the path
1036-
let matches = extractFontNameRe.exec(path);
1037-
if (matches && matches.length >= 3) {
1038-
result = matches[1];
1039-
}
1040-
else {
1041-
// give up and return the full path
1042-
result = path;
1043-
}
1044-
}
1045-
1046-
// replace spaces with underscores
1047-
if (result.includes(' ')) {
1048-
result = result.replace(/ /g, '_');
1049-
}
1050-
1051-
return result;
1052-
};
1053-
1054-
function pathToPoints(cmds, options, font) {
1055-
1056-
const parseOpts = (options, defaults) => {
1057-
if (typeof options !== 'object') {
1058-
options = defaults;
1059-
} else {
1060-
for (const key in defaults) {
1061-
if (typeof options[key] === 'undefined') {
1062-
options[key] = defaults[key];
1063-
}
1064-
}
1065-
}
1066-
return options;
1067-
}
1068-
1069-
const at = (v, i) => {
1070-
const s = v.length;
1071-
return v[i < 0 ? i % s + s : i % s];
1072-
}
1073-
1074-
const simplify = (pts, angle) => {
1075-
angle = angle || 0;
1076-
let num = 0;
1077-
for (let i = pts.length - 1; pts.length > 3 && i >= 0; --i) {
1078-
if (collinear(at(pts, i - 1), at(pts, i), at(pts, i + 1), angle)) {
1079-
pts.splice(i % pts.length, 1); // Remove middle point
1080-
num++;
1081-
}
1082-
}
1083-
return num;
1084-
}
1085-
1086-
const path = createFromCommands(arrayCommandsToObjects(cmds));
1087-
let opts = parseOpts(options, {
1088-
sampleFactor: 0.1,
1089-
simplifyThreshold: 0
1090-
});
1091-
1092-
const totalPoints = Math.ceil(path.getTotalLength() * opts.sampleFactor);
1093-
let points = [];
1094-
1095-
const mode = font._pInst.angleMode();
1096-
const DEGREES = font._pInst.DEGREES;
1097-
for (let i = 0; i < totalPoints; i++) {
1098-
const length = path.getTotalLength() * (i / (totalPoints - 1));
1099-
points.push({
1100-
...path.getPointAtLength(length),
1101-
get angle() {
1102-
const angle = path.getAngleAtLength(length);
1103-
if (mode === DEGREES) {
1104-
return angle * 180 / Math.PI;
1105-
} else {
1106-
return angle;
1107-
}
1108-
},
1109-
// For backwards compatibility
1110-
get alpha() {
1111-
return this.angle;
1112-
}
1113-
});
1114-
}
1115-
1116-
if (opts.simplifyThreshold) {
1117-
simplify(points, opts.simplifyThreshold);
1118-
}
1119-
1120-
return points;
1121-
}
1122-
1123-
function unquote(name) {
1124-
// Unquote name from CSS
1125-
if ((name.startsWith('"') || name.startsWith("'")) && name.at(0) === name.at(-1)) {
1126-
return name.slice(1, -1).replace(/\/(['"])/g, '$1');
1127-
}
1128-
return name;
1129-
}
1130-
1131-
1132976
};
1133977

1134978
// Convert arrays to named objects

0 commit comments

Comments
 (0)