textX,Y,key:val...

  anchor anchorPos (center, n, nw, ...)
  font fontName
  justify how (left, right, or center)
  text string (**)
  width lineLength

 (**) text with embedded spaces can be specified only via a param command
176865
def text args, key_args
      anchor, font, justify, text =
      key_args.values_at(*%w{anchor font justify text})
       # width handled by handle_generic_config
      
      proc do |tkaroid, cos_r, sin_r|
        x = tkaroid.x
        y = tkaroid.y
        params = tkaroid.params

        xv, yv = args.map {|arg| arg[params] rescue arg}
        coords = [
          x + xv * cos_r - yv * sin_r,
          y + xv * sin_r + yv * cos_r
        ]
        
        config = {}
        handle_generic_config(config, params, key_args)

        if anchor
          config[:anchor] = anchor[params] rescue anchor
        end
        if font
          config[:font] = font[params] rescue font
        end
        if justify
          config[:justify] = justify[params] rescue justify
        end
        if text
          config[:text] = text[params] rescue text
        end

        [TkcText, coords, config]
      end
    end
915416
def text_width(text):
    """"""
    (xmin, xmax, d1, d2) = get_dimension(text)
    return xmax - xmin
257808
function quoteEndPos( $tpl, &$text, $startPosition, $textLength, $quote )
    {
        $currentPosition = $startPosition;
        while ( $currentPosition < $textLength )
        {
            if ( $text[$currentPosition] == "\\" )
                ++$currentPosition;
            else if ( $text[$currentPosition] == $quote )
                return $currentPosition;
            ++$currentPosition;
        }
        return $currentPosition;
    }
958522
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;
	}
}
46959
def box_text(text, width, offset=0):
    
    box = " " * offset + "-" * (width+2) + "\n"
    box += " " * offset + "|" + text.center(width) + "|" + "\n"
    box += " " * offset + "-" * (width+2)
    return box
456455
def get_string_width(self, s):
        ""
        s = self.normalize_text(s)
        cw=self.current_font['cw']
        w=0
        l=len(s)
        if self.unifontsubset:
            for char in s:
                char = ord(char)
                if len(cw) > char:
                    w += cw[char] # ord(cw[2*char])<<8 + ord(cw[2*char+1])
                #elif (char>0 and char<128 and isset($cw[chr($char)])) { $w += $cw[chr($char)]; }
                elif (self.current_font['desc']['MissingWidth']) :
                    w += self.current_font['desc']['MissingWidth']
                #elif (isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
                else:
                    w += 500
        else:
            for i in range(0, l):
                w += cw.get(s[i],0)
        return w*self.font_size/1000.0
1082046
private short getAlignment(String value)
    {
        short ret = ALIGN_LEFT;

        if(value.equals("centre"))
            ret = ALIGN_CENTRE;
        else if(value.equals("left"))
            ret = ALIGN_LEFT;
        else if(value.equals("right"))
            ret = ALIGN_RIGHT;
        else if(value.equals("justify"))
            ret = ALIGN_JUSTIFY;
        else if(value.equals("fill"))
            ret = ALIGN_FILL;

        return ret;
    }
426320
def align_center(text, width, fill: SPACE, separator: NEWLINE)
      return text if width.nil?
      each_line(text, separator) do |line|
        width_diff = width - display_width(line)
        if width_diff > 0
          right_count = (width_diff.to_f / 2).ceil
          left_count  =  width_diff - right_count
          [fill * left_count, line, fill * right_count].join
        else
          line
        end
      end
    end
6913
def linetoraster(m):
    

    # Assumes monospaced font.
    x = 8 * len(m)
    y = 8
    return x, y, [itertools.chain(*row) for row in zip(*map(char, m))]
809338
def justify(clr, argd):
    
    methodmap = {
        '--ljust': clr.ljust,
        '--rjust': clr.rjust,
        '--center': clr.center,
    }
    for flag in methodmap:
        if argd[flag]:
            if argd[flag] in ('0', '-'):
                val = get_terminal_size(default=(80, 35))[0]
            else:
                val = try_int(argd[flag], minimum=None)
                if val < 0:
                    # Negative value, subtract from terminal width.
                    val = get_terminal_size(default=(80, 35))[0] + val
            return methodmap[flag](val)

    # No justify args given.
    return clr
1366247
function(labels, direction, step, start_offset, font_offsets, extra_font_options) {
    function x_offset(value) {
      return value * direction[0];
    }
    
    function y_offset(value) {
      return value * direction[1];
    }
    
    /* Start at the origin */
    var x = this.x_padding_left - 1 + x_offset(start_offset),
        y = this.options.height - this.y_padding_bottom + y_offset(start_offset),
        pathString = '',
        i,
        font_options = {};
    Helpers.extend(font_options, this.font_options);
    Helpers.extend(font_options, extra_font_options || {});

    for (i = 0; i < labels.length; i++) {
      pathString += 'M' + x + ',' + y;
      if (typeof labels[i] !== 'undefined' && (labels[i] + '').length > 0) {
        pathString += 'L' + (x + y_offset(5)) + ',' + (y + x_offset(5));
        this.paper.text(x + font_offsets[0], y - font_offsets[1], labels[i]).attr(font_options).toFront();
      }
      x = x + x_offset(step);
      y = y + y_offset(step);
    }

    this.paper.path(pathString).attr({ stroke: this.options.label_colour });
  }
1181350
function (str, x, y) {

		var defaultChartStyle = defaultOptions.chart.style;

		return this.createElement('span')
			.attr({
				text: str,
				x: mathRound(x),
				y: mathRound(y)
			})
			.css({
				whiteSpace: 'nowrap',
				fontFamily: defaultChartStyle.fontFamily,
				fontSize: defaultChartStyle.fontSize
			});
	}
479032
def draw_foreground
      case @justify
        when :left
          rel_x = 0.0
          draw_x = x + padding_left

        when :right
          rel_x = 1.0
          draw_x = x + rect.width - padding_right

        when :center
          rel_x = 0.5
          draw_x = (x + padding_left) + (rect.width - padding_right - padding_left) / 2.0
      end

      font.draw_rel(@text, draw_x, y + padding_top, z, rel_x, 0, 1, 1, color)
    end
1296033
function fullWidth(text, param) {
    let cols = process.stdout.columns;
    let lines = text.split('\n');

    for (i = 0; i < lines.length; i++) {
        let size = cols;
        if (i === 0) size = size - 15;
        if ((lines[i].indexOf('%') > 0) && (param !== undefined)) size = size - param.length + 2;
        while (lines[i].length < size) {
            lines[i] = lines[i] + ' ';
        }
    }
    text = lines.join('\n');

    return text;
}
742398
function _wrapText(ctx, params) {
	var allText = String(params.text),
		// Maximum line width (optional)
		maxWidth = params.maxWidth,
		// Lines created by manual line breaks (\n)
		manualLines = allText.split('\n'),
		// All lines created manually and by wrapping
		allLines = [],
		// Other variables
		lines, line, l,
		text, words, w;

	// Loop through manually-broken lines
	for (l = 0; l < manualLines.length; l += 1) {

		text = manualLines[l];
		// Split line into list of words
		words = text.split(' ');
		lines = [];
		line = '';

		// If text is short enough initially
		// Or, if the text consists of only one word
		if (words.length === 1 || ctx.measureText(text).width < maxWidth) {

			// No need to wrap text
			lines = [text];

		} else {

			// Wrap lines
			for (w = 0; w < words.length; w += 1) {

				// Once line gets too wide, push word to next line
				if (ctx.measureText(line + words[w]).width > maxWidth) {
					// This check prevents empty lines from being created
					if (line !== '') {
						lines.push(line);
					}
					// Start new line and repeat process
					line = '';
				}
				// Add words to line until the line is too wide
				line += words[w];
				// Do not add a space after the last word
				if (w !== (words.length - 1)) {
					line += ' ';
				}
			}
			// The last word should always be pushed
			lines.push(line);

		}
		// Remove extra space at the end of each line
		allLines = allLines.concat(
			lines
			.join('\n')
			.replace(/((\n))|($)/gi, '$2')
			.split('\n')
		);

	}

	return allLines;
}
453622
def get_text_alignment(pos):
    """"""
    pos = pos.lower()  # to make it case insensitive
    va, ha = None, None
    if pos == 'nw': va, ha = 'top', 'left'
    elif pos == 'ne': va, ha = 'top', 'right'
    elif pos == 'sw': va, ha = 'bottom', 'left'
    elif pos == 'se': va, ha = 'bottom', 'right'
    else: raise ValueError("Unknown value for 'pos': %s" % (str(pos)))
    return {'va':va, 'ha':ha}
525419
function defineFix(valueToken, valueInfo) {
            const text = valueToken.htmlValue
            if (text !== valueToken.value) {
                // can not fix
                return undefined
            }
            const quoteChar = GET_FIX_QUOTE_CHARS[option](valueInfo)

            const quotePattern = quoteChar === '"' ? /"/gu : /'/gu
            const quoteEscaped = quoteChar === '"' ? "&quot;" : "&apos;"
            return fixer => {
                const replacement =
                    quoteChar +
                    valueInfo.content.replace(quotePattern, quoteEscaped) +
                    quoteChar
                return fixer.replaceText(valueToken, replacement)
            }
        }