public virtual void testMethods() { String str = "This is a string"; String chrString = AsString.charAt(str, 0); float chrCode = AsString.charCodeAt(str, 0); String fromCharCode = AsString.fromCharCode(0); int indexOf = AsString.indexOf(str, "string"); indexOf = AsString.indexOf(str, "string", 0); String replace = AsString.replace(str, "string", "foo"); String slice = AsString.slice(str, 0); slice = AsString.slice(str, 0, 10); AsArray split = AsString.split(str, " "); String substr = AsString.substr(str, 0); substr = AsString.substring(str, 0, 10); String substring = AsString.substring(str, 0); substring = AsString.substring(str, 0, 10); String toLocalLowerCase = AsString.toLocaleLowerCase(str); String toLocalUpperCase = AsString.toLocaleUpperCase(str); String toLowerCase = AsString.toLowerCase(str); String toUpperCase = AsString.toUpperCase(str); String toString = str.ToString(); String valueOf = AsString.valueOf(str); }
private AsVector <AsCharLocation> arrangeChars(float width, float height, String text, float fontSize, String hAlign, String vAlign, bool autoScale, bool kerning) { if (text == null || text.Length == 0) { return(new AsVector <AsCharLocation>()); } if (fontSize < 0) { fontSize = fontSize * -mSize; } AsVector <AsVector <AsCharLocation> > lines = null; bool finished = false; AsCharLocation charLocation = null; int numChars = 0; float containerWidth = 0; float containerHeight = 0; float scale = 0; while (!finished) { scale = fontSize / mSize; containerWidth = width / scale; containerHeight = height / scale; lines = new AsVector <AsVector <AsCharLocation> >(); if (mLineHeight <= containerHeight) { int lastWhiteSpace = -1; int lastCharID = -1; float currentX = 0; float currentY = 0; AsVector <AsCharLocation> currentLine = new AsVector <AsCharLocation>(); numChars = text.Length; int i = 0; for (; i < numChars; ++i) { bool lineFull = false; int charID = (int)(AsString.charCodeAt(text, i)); AsBitmapChar _char = getChar(charID); if (charID == CHAR_NEWLINE || charID == CHAR_CARRIAGE_RETURN) { lineFull = true; } else { if (_char == null) { AsGlobal.trace("[Starling] Missing character: " + charID); } else { if (charID == CHAR_SPACE || charID == CHAR_TAB) { lastWhiteSpace = i; } if (kerning) { currentX = currentX + _char.getKerning(lastCharID); } charLocation = mCharLocationPool.getLength() != 0 ? mCharLocationPool.pop() : new AsCharLocation(_char); charLocation._char = _char; charLocation.x = currentX + _char.getXOffset(); charLocation.y = currentY + _char.getYOffset(); currentLine.push(charLocation); currentX = currentX + _char.getXAdvance(); lastCharID = charID; if (currentLine.getLength() == 1) { currentX = currentX - _char.getXOffset(); charLocation.x = charLocation.x - _char.getXOffset(); } if (charLocation.x + _char.getWidth() > containerWidth) { int numCharsToRemove = lastWhiteSpace == -1 ? 1 : i - lastWhiteSpace; int removeIndex = (int)(currentLine.getLength() - numCharsToRemove); currentLine.splice(removeIndex, (uint)(numCharsToRemove)); if (currentLine.getLength() == 0) { break; } i = i - numCharsToRemove; lineFull = true; } } } if (i == numChars - 1) { lines.push(currentLine); finished = true; } else { if (lineFull) { lines.push(currentLine); if (lastWhiteSpace == i) { currentLine.pop(); } if (currentY + 2 * mLineHeight <= containerHeight) { currentLine = new AsVector <AsCharLocation>(); currentX = 0; currentY = currentY + mLineHeight; lastWhiteSpace = -1; lastCharID = -1; } else { break; } } } } } if (autoScale && !finished) { fontSize = fontSize - 1; lines.setLength(0); } else { finished = true; } } AsVector <AsCharLocation> finalLocations = new AsVector <AsCharLocation>(); int numLines = (int)(lines.getLength()); float bottom = currentY + mLineHeight; int yOffset = 0; if (vAlign == AsVAlign.BOTTOM) { yOffset = (int)(containerHeight - bottom); } else { if (vAlign == AsVAlign.CENTER) { yOffset = (int)((containerHeight - bottom) / 2); } } int lineID = 0; for (; lineID < numLines; ++lineID) { AsVector <AsCharLocation> line = lines[lineID]; numChars = (int)(line.getLength()); if (numChars == 0) { continue; } AsCharLocation lastLocation = line[line.getLength() - 1]; float right = lastLocation.x + lastLocation._char.getWidth(); int xOffset = 0; if (hAlign == AsHAlign.RIGHT) { xOffset = (int)(containerWidth - right); } else { if (hAlign == AsHAlign.CENTER) { xOffset = (int)((containerWidth - right) / 2); } } int c = 0; for (; c < numChars; ++c) { charLocation = line[c]; charLocation.x = scale * (charLocation.x + xOffset); charLocation.y = scale * (charLocation.y + yOffset); charLocation.scale = scale; if (charLocation._char.getWidth() > 0 && charLocation._char.getHeight() > 0) { finalLocations.push(charLocation); } mCharLocationPool.push(charLocation); } } return(finalLocations); }