dist/jcanvas.js
function _measureText(canvas, ctx, params, lines) {
	var originalSize, curWidth, l,
		propCache = caches.propCache;

	// Used cached width/height if possible
	if (propCache.text === params.text && propCache.fontStyle === params.fontStyle && propCache.fontSize === params.fontSize && propCache.fontFamily === params.fontFamily && propCache.maxWidth === params.maxWidth && propCache.lineHeight === params.lineHeight) {

		params.width = propCache.width;
		params.height = propCache.height;

	} else {
		// Calculate text dimensions only once

		// Calculate width of first line (for comparison)
		params.width = ctx.measureText(lines[0]).width;

		// Get width of longest line
		for (l = 1; l < lines.length; l += 1) {

			curWidth = ctx.measureText(lines[l]).width;
			// Ensure text's width is the width of its longest line
			if (curWidth > params.width) {
				params.width = curWidth;
			}

		}

		// Save original font size
		originalSize = canvas.style.fontSize;
		// Temporarily set canvas font size to retrieve size in pixels
		canvas.style.fontSize = params.fontSize;
		// Save text width and height in parameters object
		params.height = parseFloat($.css(canvas, 'fontSize')) * lines.length * params.lineHeight;
		// Reset font size to original size
		canvas.style.fontSize = originalSize;
	}
}
function _measureText(canvas, ctx, params, lines) {
	var originalSize, curWidth, l,
		propCache = caches.propCache;

	// Used cached width/height if possible
	if (propCache.text === params.text && propCache.fontStyle === params.fontStyle && propCache.fontSize === params.fontSize && propCache.fontFamily === params.fontFamily && propCache.maxWidth === params.maxWidth && propCache.lineHeight === params.lineHeight) {

		params.width = propCache.width;
		params.height = propCache.height;

	} else {
		// Calculate text dimensions only once

		// Calculate width of first line (for comparison)
		params.width = ctx.measureText(lines[0]).width;

		// Get width of longest line
		for (l = 1; l < lines.length; l += 1) {

			curWidth = ctx.measureText(lines[l]).width;
			// Ensure text's width is the width of its longest line
			if (curWidth > params.width) {
				params.width = curWidth;
			}

		}

		// Save original font size
		originalSize = canvas.style.fontSize;
		// Temporarily set canvas font size to retrieve size in pixels
		canvas.style.fontSize = params.fontSize;
		// Save text width and height in parameters object
		params.height = parseFloat($.css(canvas, 'fontSize')) * lines.length * params.lineHeight;
		// Reset font size to original size
		canvas.style.fontSize = originalSize;
	}
}
function _measureText ( canvas , ctx , params , lines ) { var originalSize , curWidth , l , propCache = caches . propCache ; // Used cached width/height if possible if ( propCache . text === params . text && propCache . fontStyle === params . fontStyle && propCache . fontSize === params . fontSize && propCache . fontFamily === params . fontFamily && propCache . maxWidth === params . maxWidth && propCache . lineHeight === params . lineHeight ) { params . width = propCache . width ; params . height = propCache . height ; } else { // Calculate text dimensions only once // Calculate width of first line (for comparison) params . width = ctx . measureText ( lines [ 0 ] ) . width ; // Get width of longest line for ( l = 1 ; l < lines . length ; l += 1 ) { curWidth = ctx . measureText ( lines [ l ] ) . width ; // Ensure text's width is the width of its longest line if ( curWidth > params . width ) { params . width = curWidth ; } } // Save original font size originalSize = canvas . style . fontSize ; // Temporarily set canvas font size to retrieve size in pixels canvas . style . fontSize = params . fontSize ; // Save text width and height in parameters object params . height = parseFloat ( $ . css ( canvas , 'fontSize' ) ) * lines . length * params . lineHeight ; // Reset font size to original size canvas . style . fontSize = originalSize ; } }
Measures canvas text
Measures canvas text