Add bolding for plusses
This commit is contained in:
		| @@ -66,16 +66,31 @@ const pieceDef = <T extends Piece["type"], M extends PieceMeasure>( | |||||||
| const textPiece = pieceDef({ | const textPiece = pieceDef({ | ||||||
| 	type: "text", | 	type: "text", | ||||||
| 	measure(context, piece) { | 	measure(context, piece) { | ||||||
|  | 		context.save(); | ||||||
|  | 		const fontInfo = parseFont(context.font); | ||||||
|  | 		if (piece.isBold) { | ||||||
|  | 			fontInfo.weight = "bold"; | ||||||
|  | 		} | ||||||
|  | 		if (piece.isItalic) { | ||||||
|  | 			fontInfo.style = "italic"; | ||||||
|  | 		} | ||||||
|  | 		const font = stringifyFont(fontInfo); | ||||||
|  | 		context.font = font; | ||||||
| 		const metrics = context.measureText(piece.text); | 		const metrics = context.measureText(piece.text); | ||||||
|  | 		context.restore(); | ||||||
| 		return { | 		return { | ||||||
| 			type: "content", | 			type: "content", | ||||||
| 			width: metrics.width, | 			width: metrics.width, | ||||||
| 			ascent: metrics.fontBoundingBoxAscent, | 			ascent: metrics.fontBoundingBoxAscent, | ||||||
| 			descent: metrics.fontBoundingBoxDescent, | 			descent: metrics.fontBoundingBoxDescent, | ||||||
|  | 			font, | ||||||
| 		}; | 		}; | ||||||
| 	}, | 	}, | ||||||
| 	render(context, piece, x, y) { | 	render(context, piece, x, y, measure) { | ||||||
|  | 		context.save(); | ||||||
|  | 		context.font = measure.font; | ||||||
| 		context.fillText(piece.text, x, y); | 		context.fillText(piece.text, x, y); | ||||||
|  | 		context.restore(); | ||||||
| 	}, | 	}, | ||||||
| }); | }); | ||||||
|  |  | ||||||
| @@ -100,8 +115,8 @@ const breakPiece = pieceDef({ | |||||||
| 		return { | 		return { | ||||||
| 			type: "break", | 			type: "break", | ||||||
| 			width: 0, | 			width: 0, | ||||||
| 			ascent: metrics.fontBoundingBoxAscent, | 			ascent: metrics.fontBoundingBoxAscent / 3, | ||||||
| 			descent: metrics.fontBoundingBoxDescent, | 			descent: metrics.fontBoundingBoxDescent / 3, | ||||||
| 		}; | 		}; | ||||||
| 	}, | 	}, | ||||||
| 	render() {}, | 	render() {}, | ||||||
| @@ -310,6 +325,23 @@ export const parse = (text: string): Piece[] => { | |||||||
| 			const end = text.slice(i).match(/\$\d*/)![0].length; | 			const end = text.slice(i).match(/\$\d*/)![0].length; | ||||||
| 			pieces.push({ type: "coin", text: text.slice(i + 1, i + end) }); | 			pieces.push({ type: "coin", text: text.slice(i + 1, i + end) }); | ||||||
| 			i += end - 1; | 			i += end - 1; | ||||||
|  | 		} else if (char === "+") { | ||||||
|  | 			const match = text.slice(i).match(/\+\d* \S+/); | ||||||
|  | 			if (match) { | ||||||
|  | 				const end = match[0].length; | ||||||
|  | 				pieces.push({ | ||||||
|  | 					type: "text", | ||||||
|  | 					isBold: true, | ||||||
|  | 					text: text.slice(i, i + end), | ||||||
|  | 				}); | ||||||
|  | 				i += end - 1; | ||||||
|  | 			} else { | ||||||
|  | 				pieces.push({ | ||||||
|  | 					type: "text", | ||||||
|  | 					isBold: true, | ||||||
|  | 					text: "+", | ||||||
|  | 				}); | ||||||
|  | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			const end = text.slice(i).match(/[^$ \n]+/)![0].length; | 			const end = text.slice(i).match(/[^$ \n]+/)![0].length; | ||||||
| 			pieces.push({ type: "text", text: text.slice(i, i + end) }); | 			pieces.push({ type: "text", text: text.slice(i, i + end) }); | ||||||
|   | |||||||
| @@ -159,8 +159,8 @@ const drawStandardCard = async ( | |||||||
| 		context, | 		context, | ||||||
| 		parse(card.description), | 		parse(card.description), | ||||||
| 		w / 2, | 		w / 2, | ||||||
| 		1520, | 		1490, | ||||||
| 		1100 | 		1000 | ||||||
| 	); | 	); | ||||||
| 	// Draw the types | 	// Draw the types | ||||||
| 	let size = 65; | 	let size = 65; | ||||||
|   | |||||||
| @@ -8,7 +8,8 @@ import { | |||||||
| export const sampleCard1: DominionCard = { | export const sampleCard1: DominionCard = { | ||||||
| 	orientation: "card", | 	orientation: "card", | ||||||
| 	title: "Title", | 	title: "Title", | ||||||
| 	description: "Hello, world.", | 	description: | ||||||
|  | 		"+1 Action\n\nReveal the top card of your deck. If it's an Action card, put it into your hand.", | ||||||
| 	types: [TYPE_ACTION, TYPE_REACTION], | 	types: [TYPE_ACTION, TYPE_REACTION], | ||||||
| 	image: "https://wiki.dominionstrategy.com/images/7/76/AdventurerArt.jpg", | 	image: "https://wiki.dominionstrategy.com/images/7/76/AdventurerArt.jpg", | ||||||
| 	artist: "Dall-E", | 	artist: "Dall-E", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user