id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
sequence
docstring
stringlengths
3
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
105
339
1,700
nguillaumin/slick2d-maven
slick2d-peditor/src/main/java/org/newdawn/slick/tools/peditor/ParticleGame.java
ParticleGame.setSystem
public void setSystem(ParticleSystem system) { this.system = system; emitters.clear(); system.setRemoveCompletedEmitters(false); for (int i = 0; i < system.getEmitterCount(); i++) { emitters.add(system.getEmitter(i)); } }
java
public void setSystem(ParticleSystem system) { this.system = system; emitters.clear(); system.setRemoveCompletedEmitters(false); for (int i = 0; i < system.getEmitterCount(); i++) { emitters.add(system.getEmitter(i)); } }
[ "public", "void", "setSystem", "(", "ParticleSystem", "system", ")", "{", "this", ".", "system", "=", "system", ";", "emitters", ".", "clear", "(", ")", ";", "system", ".", "setRemoveCompletedEmitters", "(", "false", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "system", ".", "getEmitterCount", "(", ")", ";", "i", "++", ")", "{", "emitters", ".", "add", "(", "system", ".", "getEmitter", "(", "i", ")", ")", ";", "}", "}" ]
Set the particle system to be displayed @param system The system to be displayed
[ "Set", "the", "particle", "system", "to", "be", "displayed" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-peditor/src/main/java/org/newdawn/slick/tools/peditor/ParticleGame.java#L198-L205
1,701
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/CharSet.java
CharSet.copy
public CharSet copy() { CharSet copy = new CharSet(); copy.name = name; copy.source = source; copy.mutable = true; copy.chars = new boolean[256]; System.arraycopy(chars, 0, copy.chars, 0, chars.length); return copy; }
java
public CharSet copy() { CharSet copy = new CharSet(); copy.name = name; copy.source = source; copy.mutable = true; copy.chars = new boolean[256]; System.arraycopy(chars, 0, copy.chars, 0, chars.length); return copy; }
[ "public", "CharSet", "copy", "(", ")", "{", "CharSet", "copy", "=", "new", "CharSet", "(", ")", ";", "copy", ".", "name", "=", "name", ";", "copy", ".", "source", "=", "source", ";", "copy", ".", "mutable", "=", "true", ";", "copy", ".", "chars", "=", "new", "boolean", "[", "256", "]", ";", "System", ".", "arraycopy", "(", "chars", ",", "0", ",", "copy", ".", "chars", ",", "0", ",", "chars", ".", "length", ")", ";", "return", "copy", ";", "}" ]
Copy this character set @return A copy of this character set
[ "Copy", "this", "character", "set" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/CharSet.java#L60-L70
1,702
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/CharSet.java
CharSet.save
public void save(File file) throws IOException { DataOutputStream dout = new DataOutputStream(new FileOutputStream(file)); dout.writeUTF(name); for (int i=0;i<256;i++) { dout.writeBoolean(chars[i]); } dout.close(); }
java
public void save(File file) throws IOException { DataOutputStream dout = new DataOutputStream(new FileOutputStream(file)); dout.writeUTF(name); for (int i=0;i<256;i++) { dout.writeBoolean(chars[i]); } dout.close(); }
[ "public", "void", "save", "(", "File", "file", ")", "throws", "IOException", "{", "DataOutputStream", "dout", "=", "new", "DataOutputStream", "(", "new", "FileOutputStream", "(", "file", ")", ")", ";", "dout", ".", "writeUTF", "(", "name", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "256", ";", "i", "++", ")", "{", "dout", ".", "writeBoolean", "(", "chars", "[", "i", "]", ")", ";", "}", "dout", ".", "close", "(", ")", ";", "}" ]
Save the set to a file @param file The file to save to @throws IOException Indicates a failure to write to disk
[ "Save", "the", "set", "to", "a", "file" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/CharSet.java#L105-L112
1,703
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/geom/Path.java
Path.lineTo
public void lineTo(float x, float y) { if (hole != null) { hole.add(new float[] {x,y}); } else { localPoints.add(new float[] {x,y}); } cx = x; cy = y; pointsDirty = true; }
java
public void lineTo(float x, float y) { if (hole != null) { hole.add(new float[] {x,y}); } else { localPoints.add(new float[] {x,y}); } cx = x; cy = y; pointsDirty = true; }
[ "public", "void", "lineTo", "(", "float", "x", ",", "float", "y", ")", "{", "if", "(", "hole", "!=", "null", ")", "{", "hole", ".", "add", "(", "new", "float", "[", "]", "{", "x", ",", "y", "}", ")", ";", "}", "else", "{", "localPoints", ".", "add", "(", "new", "float", "[", "]", "{", "x", ",", "y", "}", ")", ";", "}", "cx", "=", "x", ";", "cy", "=", "y", ";", "pointsDirty", "=", "true", ";", "}" ]
Add a line to the contour or hole which ends at the specified location. @param x The x coordinate to draw the line to @param y The y coordiante to draw the line to
[ "Add", "a", "line", "to", "the", "contour", "or", "hole", "which", "ends", "at", "the", "specified", "location", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/geom/Path.java#L56-L65
1,704
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/geom/Path.java
Path.transform
private ArrayList transform(ArrayList pts, Transform t) { float[] in = new float[pts.size()*2]; float[] out = new float[pts.size()*2]; for (int i=0;i<pts.size();i++) { in[i*2] = ((float[]) pts.get(i))[0]; in[(i*2)+1] = ((float[]) pts.get(i))[1]; } t.transform(in, 0, out, 0, pts.size()); ArrayList outList = new ArrayList(); for (int i=0;i<pts.size();i++) { outList.add(new float[] {out[(i*2)],out[(i*2)+1]}); } return outList; }
java
private ArrayList transform(ArrayList pts, Transform t) { float[] in = new float[pts.size()*2]; float[] out = new float[pts.size()*2]; for (int i=0;i<pts.size();i++) { in[i*2] = ((float[]) pts.get(i))[0]; in[(i*2)+1] = ((float[]) pts.get(i))[1]; } t.transform(in, 0, out, 0, pts.size()); ArrayList outList = new ArrayList(); for (int i=0;i<pts.size();i++) { outList.add(new float[] {out[(i*2)],out[(i*2)+1]}); } return outList; }
[ "private", "ArrayList", "transform", "(", "ArrayList", "pts", ",", "Transform", "t", ")", "{", "float", "[", "]", "in", "=", "new", "float", "[", "pts", ".", "size", "(", ")", "*", "2", "]", ";", "float", "[", "]", "out", "=", "new", "float", "[", "pts", ".", "size", "(", ")", "*", "2", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pts", ".", "size", "(", ")", ";", "i", "++", ")", "{", "in", "[", "i", "*", "2", "]", "=", "(", "(", "float", "[", "]", ")", "pts", ".", "get", "(", "i", ")", ")", "[", "0", "]", ";", "in", "[", "(", "i", "*", "2", ")", "+", "1", "]", "=", "(", "(", "float", "[", "]", ")", "pts", ".", "get", "(", "i", ")", ")", "[", "1", "]", ";", "}", "t", ".", "transform", "(", "in", ",", "0", ",", "out", ",", "0", ",", "pts", ".", "size", "(", ")", ")", ";", "ArrayList", "outList", "=", "new", "ArrayList", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pts", ".", "size", "(", ")", ";", "i", "++", ")", "{", "outList", ".", "add", "(", "new", "float", "[", "]", "{", "out", "[", "(", "i", "*", "2", ")", "]", ",", "out", "[", "(", "i", "*", "2", ")", "+", "1", "]", "}", ")", ";", "}", "return", "outList", ";", "}" ]
Transform a list of points @param pts The pts to transform @param t The transform to apply @return The transformed points
[ "Transform", "a", "list", "of", "points" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/geom/Path.java#L155-L171
1,705
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/svg/NonGeometricData.java
NonGeometricData.morphColor
private String morphColor(String str) { if (str.equals("")) { return "#000000"; } if (str.equals("white")) { return "#ffffff"; } if (str.equals("black")) { return "#000000"; } return str; }
java
private String morphColor(String str) { if (str.equals("")) { return "#000000"; } if (str.equals("white")) { return "#ffffff"; } if (str.equals("black")) { return "#000000"; } return str; }
[ "private", "String", "morphColor", "(", "String", "str", ")", "{", "if", "(", "str", ".", "equals", "(", "\"\"", ")", ")", "{", "return", "\"#000000\"", ";", "}", "if", "(", "str", ".", "equals", "(", "\"white\"", ")", ")", "{", "return", "\"#ffffff\"", ";", "}", "if", "(", "str", ".", "equals", "(", "\"black\"", ")", ")", "{", "return", "\"#000000\"", ";", "}", "return", "str", ";", "}" ]
Morph the color from a string @param str The string to morph @return The new color string
[ "Morph", "the", "color", "from", "a", "string" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/svg/NonGeometricData.java#L57-L69
1,706
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/svg/NonGeometricData.java
NonGeometricData.addAttribute
public void addAttribute(String attribute, String value) { if (value == null) { value = ""; } if (attribute.equals(FILL) ) { value = morphColor(value); } if (attribute.equals(STROKE_OPACITY)) { if (value.equals("0")) { props.setProperty(STROKE, "none"); } } if (attribute.equals(STROKE_WIDTH)) { if (value.equals("")) { value = "1"; } if (value.endsWith("px")) { value = value.substring(0,value.length()-2); } } if (attribute.equals(STROKE)) { if ("none".equals(props.getProperty(STROKE))) { return; } if ("".equals(props.getProperty(STROKE))) { return; } value = morphColor(value); } props.setProperty(attribute, value); }
java
public void addAttribute(String attribute, String value) { if (value == null) { value = ""; } if (attribute.equals(FILL) ) { value = morphColor(value); } if (attribute.equals(STROKE_OPACITY)) { if (value.equals("0")) { props.setProperty(STROKE, "none"); } } if (attribute.equals(STROKE_WIDTH)) { if (value.equals("")) { value = "1"; } if (value.endsWith("px")) { value = value.substring(0,value.length()-2); } } if (attribute.equals(STROKE)) { if ("none".equals(props.getProperty(STROKE))) { return; } if ("".equals(props.getProperty(STROKE))) { return; } value = morphColor(value); } props.setProperty(attribute, value); }
[ "public", "void", "addAttribute", "(", "String", "attribute", ",", "String", "value", ")", "{", "if", "(", "value", "==", "null", ")", "{", "value", "=", "\"\"", ";", "}", "if", "(", "attribute", ".", "equals", "(", "FILL", ")", ")", "{", "value", "=", "morphColor", "(", "value", ")", ";", "}", "if", "(", "attribute", ".", "equals", "(", "STROKE_OPACITY", ")", ")", "{", "if", "(", "value", ".", "equals", "(", "\"0\"", ")", ")", "{", "props", ".", "setProperty", "(", "STROKE", ",", "\"none\"", ")", ";", "}", "}", "if", "(", "attribute", ".", "equals", "(", "STROKE_WIDTH", ")", ")", "{", "if", "(", "value", ".", "equals", "(", "\"\"", ")", ")", "{", "value", "=", "\"1\"", ";", "}", "if", "(", "value", ".", "endsWith", "(", "\"px\"", ")", ")", "{", "value", "=", "value", ".", "substring", "(", "0", ",", "value", ".", "length", "(", ")", "-", "2", ")", ";", "}", "}", "if", "(", "attribute", ".", "equals", "(", "STROKE", ")", ")", "{", "if", "(", "\"none\"", ".", "equals", "(", "props", ".", "getProperty", "(", "STROKE", ")", ")", ")", "{", "return", ";", "}", "if", "(", "\"\"", ".", "equals", "(", "props", ".", "getProperty", "(", "STROKE", ")", ")", ")", "{", "return", ";", "}", "value", "=", "morphColor", "(", "value", ")", ";", "}", "props", ".", "setProperty", "(", "attribute", ",", "value", ")", ";", "}" ]
Add a configured style attribute into the data set @param attribute The attribute to add @param value The value to assign
[ "Add", "a", "configured", "style", "attribute", "into", "the", "data", "set" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/svg/NonGeometricData.java#L77-L109
1,707
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/svg/NonGeometricData.java
NonGeometricData.getAsColor
public Color getAsColor(String attribute) { if (!isColor(attribute)) { throw new RuntimeException("Attribute "+attribute+" is not specified as a color:"+getAttribute(attribute)); } int col = Integer.parseInt(getAttribute(attribute).substring(1), 16); return new Color(col); }
java
public Color getAsColor(String attribute) { if (!isColor(attribute)) { throw new RuntimeException("Attribute "+attribute+" is not specified as a color:"+getAttribute(attribute)); } int col = Integer.parseInt(getAttribute(attribute).substring(1), 16); return new Color(col); }
[ "public", "Color", "getAsColor", "(", "String", "attribute", ")", "{", "if", "(", "!", "isColor", "(", "attribute", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"Attribute \"", "+", "attribute", "+", "\" is not specified as a color:\"", "+", "getAttribute", "(", "attribute", ")", ")", ";", "}", "int", "col", "=", "Integer", ".", "parseInt", "(", "getAttribute", "(", "attribute", ")", ".", "substring", "(", "1", ")", ",", "16", ")", ";", "return", "new", "Color", "(", "col", ")", ";", "}" ]
Get an attribute value converted to a color. isColor should first be checked @param attribute The attribute whose value should be interpreted as a color @return The color based on the attribute
[ "Get", "an", "attribute", "value", "converted", "to", "a", "color", ".", "isColor", "should", "first", "be", "checked" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/svg/NonGeometricData.java#L147-L155
1,708
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/svg/NonGeometricData.java
NonGeometricData.getAsFloat
public float getAsFloat(String attribute) { String value = getAttribute(attribute); if (value == null) { return 0; } try { return Float.parseFloat(value); } catch (NumberFormatException e) { throw new RuntimeException("Attribute "+attribute+" is not specified as a float:"+getAttribute(attribute)); } }
java
public float getAsFloat(String attribute) { String value = getAttribute(attribute); if (value == null) { return 0; } try { return Float.parseFloat(value); } catch (NumberFormatException e) { throw new RuntimeException("Attribute "+attribute+" is not specified as a float:"+getAttribute(attribute)); } }
[ "public", "float", "getAsFloat", "(", "String", "attribute", ")", "{", "String", "value", "=", "getAttribute", "(", "attribute", ")", ";", "if", "(", "value", "==", "null", ")", "{", "return", "0", ";", "}", "try", "{", "return", "Float", ".", "parseFloat", "(", "value", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "\"Attribute \"", "+", "attribute", "+", "\" is not specified as a float:\"", "+", "getAttribute", "(", "attribute", ")", ")", ";", "}", "}" ]
Get an attribute converted to a float value @param attribute The attribute to retrieve @return The float value derived from the attribute
[ "Get", "an", "attribute", "converted", "to", "a", "float", "value" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/svg/NonGeometricData.java#L180-L191
1,709
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/font/GlyphPage.java
GlyphPage.loadGlyphs
public int loadGlyphs (List glyphs, int maxGlyphsToLoad) throws SlickException { if (rowHeight != 0 && maxGlyphsToLoad == -1) { // If this page has glyphs and we are not loading incrementally, return zero if any of the glyphs don't fit. int testX = pageX; int testY = pageY; int testRowHeight = rowHeight; for (Iterator iter = getIterator(glyphs); iter.hasNext();) { Glyph glyph = (Glyph)iter.next(); int width = glyph.getWidth(); int height = glyph.getHeight(); if (testX + width >= pageWidth) { testX = 0; testY += testRowHeight; testRowHeight = height; } else if (height > testRowHeight) { testRowHeight = height; } if (testY + testRowHeight >= pageWidth) return 0; testX += width; } } Color.white.bind(); pageImage.bind(); int i = 0; for (Iterator iter = getIterator(glyphs); iter.hasNext();) { Glyph glyph = (Glyph)iter.next(); int width = Math.min(MAX_GLYPH_SIZE, glyph.getWidth()); int height = Math.min(MAX_GLYPH_SIZE, glyph.getHeight()); if (rowHeight == 0) { // The first glyph always fits. rowHeight = height; } else { // Wrap to the next line if needed, or break if no more fit. if (pageX + width >= pageWidth) { if (pageY + rowHeight + height >= pageHeight) break; pageX = 0; pageY += rowHeight; rowHeight = height; } else if (height > rowHeight) { if (pageY + height >= pageHeight) break; rowHeight = height; } } renderGlyph(glyph, width, height); pageGlyphs.add(glyph); pageX += width; iter.remove(); i++; if (i == maxGlyphsToLoad) { // If loading incrementally, flip orderAscending so it won't change, since we'll probably load the rest next time. orderAscending = !orderAscending; break; } } TextureImpl.bindNone(); // Every other batch of glyphs added to a page are sorted the opposite way to attempt to keep same size glyps together. orderAscending = !orderAscending; return i; }
java
public int loadGlyphs (List glyphs, int maxGlyphsToLoad) throws SlickException { if (rowHeight != 0 && maxGlyphsToLoad == -1) { // If this page has glyphs and we are not loading incrementally, return zero if any of the glyphs don't fit. int testX = pageX; int testY = pageY; int testRowHeight = rowHeight; for (Iterator iter = getIterator(glyphs); iter.hasNext();) { Glyph glyph = (Glyph)iter.next(); int width = glyph.getWidth(); int height = glyph.getHeight(); if (testX + width >= pageWidth) { testX = 0; testY += testRowHeight; testRowHeight = height; } else if (height > testRowHeight) { testRowHeight = height; } if (testY + testRowHeight >= pageWidth) return 0; testX += width; } } Color.white.bind(); pageImage.bind(); int i = 0; for (Iterator iter = getIterator(glyphs); iter.hasNext();) { Glyph glyph = (Glyph)iter.next(); int width = Math.min(MAX_GLYPH_SIZE, glyph.getWidth()); int height = Math.min(MAX_GLYPH_SIZE, glyph.getHeight()); if (rowHeight == 0) { // The first glyph always fits. rowHeight = height; } else { // Wrap to the next line if needed, or break if no more fit. if (pageX + width >= pageWidth) { if (pageY + rowHeight + height >= pageHeight) break; pageX = 0; pageY += rowHeight; rowHeight = height; } else if (height > rowHeight) { if (pageY + height >= pageHeight) break; rowHeight = height; } } renderGlyph(glyph, width, height); pageGlyphs.add(glyph); pageX += width; iter.remove(); i++; if (i == maxGlyphsToLoad) { // If loading incrementally, flip orderAscending so it won't change, since we'll probably load the rest next time. orderAscending = !orderAscending; break; } } TextureImpl.bindNone(); // Every other batch of glyphs added to a page are sorted the opposite way to attempt to keep same size glyps together. orderAscending = !orderAscending; return i; }
[ "public", "int", "loadGlyphs", "(", "List", "glyphs", ",", "int", "maxGlyphsToLoad", ")", "throws", "SlickException", "{", "if", "(", "rowHeight", "!=", "0", "&&", "maxGlyphsToLoad", "==", "-", "1", ")", "{", "// If this page has glyphs and we are not loading incrementally, return zero if any of the glyphs don't fit.\r", "int", "testX", "=", "pageX", ";", "int", "testY", "=", "pageY", ";", "int", "testRowHeight", "=", "rowHeight", ";", "for", "(", "Iterator", "iter", "=", "getIterator", "(", "glyphs", ")", ";", "iter", ".", "hasNext", "(", ")", ";", ")", "{", "Glyph", "glyph", "=", "(", "Glyph", ")", "iter", ".", "next", "(", ")", ";", "int", "width", "=", "glyph", ".", "getWidth", "(", ")", ";", "int", "height", "=", "glyph", ".", "getHeight", "(", ")", ";", "if", "(", "testX", "+", "width", ">=", "pageWidth", ")", "{", "testX", "=", "0", ";", "testY", "+=", "testRowHeight", ";", "testRowHeight", "=", "height", ";", "}", "else", "if", "(", "height", ">", "testRowHeight", ")", "{", "testRowHeight", "=", "height", ";", "}", "if", "(", "testY", "+", "testRowHeight", ">=", "pageWidth", ")", "return", "0", ";", "testX", "+=", "width", ";", "}", "}", "Color", ".", "white", ".", "bind", "(", ")", ";", "pageImage", ".", "bind", "(", ")", ";", "int", "i", "=", "0", ";", "for", "(", "Iterator", "iter", "=", "getIterator", "(", "glyphs", ")", ";", "iter", ".", "hasNext", "(", ")", ";", ")", "{", "Glyph", "glyph", "=", "(", "Glyph", ")", "iter", ".", "next", "(", ")", ";", "int", "width", "=", "Math", ".", "min", "(", "MAX_GLYPH_SIZE", ",", "glyph", ".", "getWidth", "(", ")", ")", ";", "int", "height", "=", "Math", ".", "min", "(", "MAX_GLYPH_SIZE", ",", "glyph", ".", "getHeight", "(", ")", ")", ";", "if", "(", "rowHeight", "==", "0", ")", "{", "// The first glyph always fits.\r", "rowHeight", "=", "height", ";", "}", "else", "{", "// Wrap to the next line if needed, or break if no more fit.\r", "if", "(", "pageX", "+", "width", ">=", "pageWidth", ")", "{", "if", "(", "pageY", "+", "rowHeight", "+", "height", ">=", "pageHeight", ")", "break", ";", "pageX", "=", "0", ";", "pageY", "+=", "rowHeight", ";", "rowHeight", "=", "height", ";", "}", "else", "if", "(", "height", ">", "rowHeight", ")", "{", "if", "(", "pageY", "+", "height", ">=", "pageHeight", ")", "break", ";", "rowHeight", "=", "height", ";", "}", "}", "renderGlyph", "(", "glyph", ",", "width", ",", "height", ")", ";", "pageGlyphs", ".", "add", "(", "glyph", ")", ";", "pageX", "+=", "width", ";", "iter", ".", "remove", "(", ")", ";", "i", "++", ";", "if", "(", "i", "==", "maxGlyphsToLoad", ")", "{", "// If loading incrementally, flip orderAscending so it won't change, since we'll probably load the rest next time.\r", "orderAscending", "=", "!", "orderAscending", ";", "break", ";", "}", "}", "TextureImpl", ".", "bindNone", "(", ")", ";", "// Every other batch of glyphs added to a page are sorted the opposite way to attempt to keep same size glyps together.\r", "orderAscending", "=", "!", "orderAscending", ";", "return", "i", ";", "}" ]
Loads glyphs to the backing texture and sets the image on each loaded glyph. Loaded glyphs are removed from the list. If this page already has glyphs and maxGlyphsToLoad is -1, then this method will return 0 if all the new glyphs don't fit. This reduces texture binds when drawing since glyphs loaded at once are typically displayed together. @param glyphs The glyphs to load. @param maxGlyphsToLoad This is the maximum number of glyphs to load from the list. Set to -1 to attempt to load all the glyphs. @return The number of glyphs that were actually loaded. @throws SlickException if the glyph could not be rendered.
[ "Loads", "glyphs", "to", "the", "backing", "texture", "and", "sets", "the", "image", "on", "each", "loaded", "glyph", ".", "Loaded", "glyphs", "are", "removed", "from", "the", "list", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/font/GlyphPage.java#L119-L186
1,710
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/font/GlyphPage.java
GlyphPage.renderGlyph
private void renderGlyph(Glyph glyph, int width, int height) throws SlickException { // Draw the glyph to the scratch image using Java2D. scratchGraphics.setComposite(AlphaComposite.Clear); scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE); scratchGraphics.setComposite(AlphaComposite.SrcOver); scratchGraphics.setColor(java.awt.Color.white); for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) ((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph); glyph.setShape(null); // The shape will never be needed again. WritableRaster raster = scratchImage.getRaster(); int[] row = new int[width]; for (int y = 0; y < height; y++) { raster.getDataElements(0, y, width, 1, row); scratchIntBuffer.put(row); } GL.glTexSubImage2D(SGL.GL_TEXTURE_2D, 0, pageX, pageY, width, height, SGL.GL_BGRA, SGL.GL_UNSIGNED_BYTE, scratchByteBuffer); scratchIntBuffer.clear(); glyph.setImage(pageImage.getSubImage(pageX, pageY, width, height)); }
java
private void renderGlyph(Glyph glyph, int width, int height) throws SlickException { // Draw the glyph to the scratch image using Java2D. scratchGraphics.setComposite(AlphaComposite.Clear); scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE); scratchGraphics.setComposite(AlphaComposite.SrcOver); scratchGraphics.setColor(java.awt.Color.white); for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) ((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph); glyph.setShape(null); // The shape will never be needed again. WritableRaster raster = scratchImage.getRaster(); int[] row = new int[width]; for (int y = 0; y < height; y++) { raster.getDataElements(0, y, width, 1, row); scratchIntBuffer.put(row); } GL.glTexSubImage2D(SGL.GL_TEXTURE_2D, 0, pageX, pageY, width, height, SGL.GL_BGRA, SGL.GL_UNSIGNED_BYTE, scratchByteBuffer); scratchIntBuffer.clear(); glyph.setImage(pageImage.getSubImage(pageX, pageY, width, height)); }
[ "private", "void", "renderGlyph", "(", "Glyph", "glyph", ",", "int", "width", ",", "int", "height", ")", "throws", "SlickException", "{", "// Draw the glyph to the scratch image using Java2D.\r", "scratchGraphics", ".", "setComposite", "(", "AlphaComposite", ".", "Clear", ")", ";", "scratchGraphics", ".", "fillRect", "(", "0", ",", "0", ",", "MAX_GLYPH_SIZE", ",", "MAX_GLYPH_SIZE", ")", ";", "scratchGraphics", ".", "setComposite", "(", "AlphaComposite", ".", "SrcOver", ")", ";", "scratchGraphics", ".", "setColor", "(", "java", ".", "awt", ".", "Color", ".", "white", ")", ";", "for", "(", "Iterator", "iter", "=", "unicodeFont", ".", "getEffects", "(", ")", ".", "iterator", "(", ")", ";", "iter", ".", "hasNext", "(", ")", ";", ")", "", "(", "(", "Effect", ")", "iter", ".", "next", "(", ")", ")", ".", "draw", "(", "scratchImage", ",", "scratchGraphics", ",", "unicodeFont", ",", "glyph", ")", ";", "glyph", ".", "setShape", "(", "null", ")", ";", "// The shape will never be needed again.\r", "WritableRaster", "raster", "=", "scratchImage", ".", "getRaster", "(", ")", ";", "int", "[", "]", "row", "=", "new", "int", "[", "width", "]", ";", "for", "(", "int", "y", "=", "0", ";", "y", "<", "height", ";", "y", "++", ")", "{", "raster", ".", "getDataElements", "(", "0", ",", "y", ",", "width", ",", "1", ",", "row", ")", ";", "scratchIntBuffer", ".", "put", "(", "row", ")", ";", "}", "GL", ".", "glTexSubImage2D", "(", "SGL", ".", "GL_TEXTURE_2D", ",", "0", ",", "pageX", ",", "pageY", ",", "width", ",", "height", ",", "SGL", ".", "GL_BGRA", ",", "SGL", ".", "GL_UNSIGNED_BYTE", ",", "scratchByteBuffer", ")", ";", "scratchIntBuffer", ".", "clear", "(", ")", ";", "glyph", ".", "setImage", "(", "pageImage", ".", "getSubImage", "(", "pageX", ",", "pageY", ",", "width", ",", "height", ")", ")", ";", "}" ]
Loads a single glyph to the backing texture, if it fits. @param glyph The glyph to be rendered @param width The expected width of the glyph @param height The expected height of the glyph @throws SlickException if the glyph could not be rendered.
[ "Loads", "a", "single", "glyph", "to", "the", "backing", "texture", "if", "it", "fits", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/font/GlyphPage.java#L196-L217
1,711
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/font/GlyphPage.java
GlyphPage.getIterator
private Iterator getIterator(List glyphs) { if (orderAscending) return glyphs.iterator(); final ListIterator iter = glyphs.listIterator(glyphs.size()); return new Iterator() { public boolean hasNext () { return iter.hasPrevious(); } public Object next () { return iter.previous(); } public void remove () { iter.remove(); } }; }
java
private Iterator getIterator(List glyphs) { if (orderAscending) return glyphs.iterator(); final ListIterator iter = glyphs.listIterator(glyphs.size()); return new Iterator() { public boolean hasNext () { return iter.hasPrevious(); } public Object next () { return iter.previous(); } public void remove () { iter.remove(); } }; }
[ "private", "Iterator", "getIterator", "(", "List", "glyphs", ")", "{", "if", "(", "orderAscending", ")", "return", "glyphs", ".", "iterator", "(", ")", ";", "final", "ListIterator", "iter", "=", "glyphs", ".", "listIterator", "(", "glyphs", ".", "size", "(", ")", ")", ";", "return", "new", "Iterator", "(", ")", "{", "public", "boolean", "hasNext", "(", ")", "{", "return", "iter", ".", "hasPrevious", "(", ")", ";", "}", "public", "Object", "next", "(", ")", "{", "return", "iter", ".", "previous", "(", ")", ";", "}", "public", "void", "remove", "(", ")", "{", "iter", ".", "remove", "(", ")", ";", "}", "}", ";", "}" ]
Returns an iterator for the specified glyphs, sorted either ascending or descending. @param glyphs The glyphs to return if present @return An iterator of the sorted list of glyphs
[ "Returns", "an", "iterator", "for", "the", "specified", "glyphs", "sorted", "either", "ascending", "or", "descending", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/font/GlyphPage.java#L225-L241
1,712
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.seekTab
boolean seekTab(FontFileReader in, String name, long offset) throws IOException { TTFDirTabEntry dt = (TTFDirTabEntry)dirTabs.get(name); if (dt == null) { log.error("Dirtab " + name + " not found."); return false; } else { in.seekSet(dt.getOffset() + offset); this.currentDirTab = dt; } return true; }
java
boolean seekTab(FontFileReader in, String name, long offset) throws IOException { TTFDirTabEntry dt = (TTFDirTabEntry)dirTabs.get(name); if (dt == null) { log.error("Dirtab " + name + " not found."); return false; } else { in.seekSet(dt.getOffset() + offset); this.currentDirTab = dt; } return true; }
[ "boolean", "seekTab", "(", "FontFileReader", "in", ",", "String", "name", ",", "long", "offset", ")", "throws", "IOException", "{", "TTFDirTabEntry", "dt", "=", "(", "TTFDirTabEntry", ")", "dirTabs", ".", "get", "(", "name", ")", ";", "if", "(", "dt", "==", "null", ")", "{", "log", ".", "error", "(", "\"Dirtab \"", "+", "name", "+", "\" not found.\"", ")", ";", "return", "false", ";", "}", "else", "{", "in", ".", "seekSet", "(", "dt", ".", "getOffset", "(", ")", "+", "offset", ")", ";", "this", ".", "currentDirTab", "=", "dt", ";", "}", "return", "true", ";", "}" ]
Position inputstream to position indicated in the dirtab offset + offset @param in The reader to read the tables from @param name The table to search for @param offset The offset to start at @return True if found the table @throws IOException Indicatesa a failure to read
[ "Position", "inputstream", "to", "position", "indicated", "in", "the", "dirtab", "offset", "+", "offset" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L207-L218
1,713
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.createCMaps
private void createCMaps() { cmaps = new java.util.ArrayList(); TTFCmapEntry tce = new TTFCmapEntry(); Iterator e = unicodeMapping.listIterator(); UnicodeMapping um = (UnicodeMapping)e.next(); UnicodeMapping lastMapping = um; tce.setUnicodeStart(um.getUnicodeIndex()); tce.setGlyphStartIndex(um.getGlyphIndex()); while (e.hasNext()) { um = (UnicodeMapping)e.next(); if (((lastMapping.getUnicodeIndex() + 1) != um.getUnicodeIndex()) || ((lastMapping.getGlyphIndex() + 1) != um.getGlyphIndex())) { tce.setUnicodeEnd(lastMapping.getUnicodeIndex()); cmaps.add(tce); tce = new TTFCmapEntry(); tce.setUnicodeStart(um.getUnicodeIndex()); tce.setGlyphStartIndex(um.getGlyphIndex()); } lastMapping = um; } tce.setUnicodeEnd(um.getUnicodeIndex()); cmaps.add(tce); }
java
private void createCMaps() { cmaps = new java.util.ArrayList(); TTFCmapEntry tce = new TTFCmapEntry(); Iterator e = unicodeMapping.listIterator(); UnicodeMapping um = (UnicodeMapping)e.next(); UnicodeMapping lastMapping = um; tce.setUnicodeStart(um.getUnicodeIndex()); tce.setGlyphStartIndex(um.getGlyphIndex()); while (e.hasNext()) { um = (UnicodeMapping)e.next(); if (((lastMapping.getUnicodeIndex() + 1) != um.getUnicodeIndex()) || ((lastMapping.getGlyphIndex() + 1) != um.getGlyphIndex())) { tce.setUnicodeEnd(lastMapping.getUnicodeIndex()); cmaps.add(tce); tce = new TTFCmapEntry(); tce.setUnicodeStart(um.getUnicodeIndex()); tce.setGlyphStartIndex(um.getGlyphIndex()); } lastMapping = um; } tce.setUnicodeEnd(um.getUnicodeIndex()); cmaps.add(tce); }
[ "private", "void", "createCMaps", "(", ")", "{", "cmaps", "=", "new", "java", ".", "util", ".", "ArrayList", "(", ")", ";", "TTFCmapEntry", "tce", "=", "new", "TTFCmapEntry", "(", ")", ";", "Iterator", "e", "=", "unicodeMapping", ".", "listIterator", "(", ")", ";", "UnicodeMapping", "um", "=", "(", "UnicodeMapping", ")", "e", ".", "next", "(", ")", ";", "UnicodeMapping", "lastMapping", "=", "um", ";", "tce", ".", "setUnicodeStart", "(", "um", ".", "getUnicodeIndex", "(", ")", ")", ";", "tce", ".", "setGlyphStartIndex", "(", "um", ".", "getGlyphIndex", "(", ")", ")", ";", "while", "(", "e", ".", "hasNext", "(", ")", ")", "{", "um", "=", "(", "UnicodeMapping", ")", "e", ".", "next", "(", ")", ";", "if", "(", "(", "(", "lastMapping", ".", "getUnicodeIndex", "(", ")", "+", "1", ")", "!=", "um", ".", "getUnicodeIndex", "(", ")", ")", "||", "(", "(", "lastMapping", ".", "getGlyphIndex", "(", ")", "+", "1", ")", "!=", "um", ".", "getGlyphIndex", "(", ")", ")", ")", "{", "tce", ".", "setUnicodeEnd", "(", "lastMapping", ".", "getUnicodeIndex", "(", ")", ")", ";", "cmaps", ".", "add", "(", "tce", ")", ";", "tce", "=", "new", "TTFCmapEntry", "(", ")", ";", "tce", ".", "setUnicodeStart", "(", "um", ".", "getUnicodeIndex", "(", ")", ")", ";", "tce", ".", "setGlyphStartIndex", "(", "um", ".", "getGlyphIndex", "(", ")", ")", ";", "}", "lastMapping", "=", "um", ";", "}", "tce", ".", "setUnicodeEnd", "(", "um", ".", "getUnicodeIndex", "(", ")", ")", ";", "cmaps", ".", "add", "(", "tce", ")", ";", "}" ]
Create teh CMAPS table
[ "Create", "teh", "CMAPS", "table" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L568-L595
1,714
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.getFlags
public int getFlags() { int flags = 32; // Use Adobe Standard charset if (italicAngle != 0) { flags = flags | 64; } if (isFixedPitch != 0) { flags = flags | 2; } if (hasSerifs) { flags = flags | 1; } return flags; }
java
public int getFlags() { int flags = 32; // Use Adobe Standard charset if (italicAngle != 0) { flags = flags | 64; } if (isFixedPitch != 0) { flags = flags | 2; } if (hasSerifs) { flags = flags | 1; } return flags; }
[ "public", "int", "getFlags", "(", ")", "{", "int", "flags", "=", "32", ";", "// Use Adobe Standard charset", "if", "(", "italicAngle", "!=", "0", ")", "{", "flags", "=", "flags", "|", "64", ";", "}", "if", "(", "isFixedPitch", "!=", "0", ")", "{", "flags", "=", "flags", "|", "2", ";", "}", "if", "(", "hasSerifs", ")", "{", "flags", "=", "flags", "|", "1", ";", "}", "return", "flags", ";", "}" ]
Returns the Flags attribute of the font. @return int The Flags
[ "Returns", "the", "Flags", "attribute", "of", "the", "font", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L653-L665
1,715
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.getFontBBox
public int[] getFontBBox() { final int[] fbb = new int[4]; fbb[0] = fontBBox1; fbb[1] = fontBBox2; fbb[2] = fontBBox3; fbb[3] = fontBBox4; return fbb; }
java
public int[] getFontBBox() { final int[] fbb = new int[4]; fbb[0] = fontBBox1; fbb[1] = fontBBox2; fbb[2] = fontBBox3; fbb[3] = fontBBox4; return fbb; }
[ "public", "int", "[", "]", "getFontBBox", "(", ")", "{", "final", "int", "[", "]", "fbb", "=", "new", "int", "[", "4", "]", ";", "fbb", "[", "0", "]", "=", "fontBBox1", ";", "fbb", "[", "1", "]", "=", "fontBBox2", ";", "fbb", "[", "2", "]", "=", "fontBBox3", ";", "fbb", "[", "3", "]", "=", "fontBBox4", ";", "return", "fbb", ";", "}" ]
Returns the font bounding box. @return int[] The font bbox
[ "Returns", "the", "font", "bounding", "box", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L696-L704
1,716
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.getWidths
public int[] getWidths() { int[] wx = new int[mtxTab.length]; for (int i = 0; i < wx.length; i++) { wx[i] = (mtxTab[i].getWx()); } return wx; }
java
public int[] getWidths() { int[] wx = new int[mtxTab.length]; for (int i = 0; i < wx.length; i++) { wx[i] = (mtxTab[i].getWx()); } return wx; }
[ "public", "int", "[", "]", "getWidths", "(", ")", "{", "int", "[", "]", "wx", "=", "new", "int", "[", "mtxTab", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "wx", ".", "length", ";", "i", "++", ")", "{", "wx", "[", "i", "]", "=", "(", "mtxTab", "[", "i", "]", ".", "getWx", "(", ")", ")", ";", "}", "return", "wx", ";", "}" ]
Returns an array of character widths. @return int[] The character widths
[ "Returns", "an", "array", "of", "character", "widths", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L743-L750
1,717
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.readHorizontalHeader
protected void readHorizontalHeader(FontFileReader in) throws IOException { seekTab(in, "hhea", 4); hheaAscender = in.readTTFShort(); log.debug("hhea.Ascender: " + hheaAscender + " " + (hheaAscender)); hheaDescender = in.readTTFShort(); log.debug("hhea.Descender: " + hheaDescender + " " + (hheaDescender)); in.skip(2 + 2 + 3 * 2 + 8 * 2); nhmtx = in.readTTFUShort(); log.debug("Number of horizontal metrics: " + nhmtx); }
java
protected void readHorizontalHeader(FontFileReader in) throws IOException { seekTab(in, "hhea", 4); hheaAscender = in.readTTFShort(); log.debug("hhea.Ascender: " + hheaAscender + " " + (hheaAscender)); hheaDescender = in.readTTFShort(); log.debug("hhea.Descender: " + hheaDescender + " " + (hheaDescender)); in.skip(2 + 2 + 3 * 2 + 8 * 2); nhmtx = in.readTTFUShort(); log.debug("Number of horizontal metrics: " + nhmtx); }
[ "protected", "void", "readHorizontalHeader", "(", "FontFileReader", "in", ")", "throws", "IOException", "{", "seekTab", "(", "in", ",", "\"hhea\"", ",", "4", ")", ";", "hheaAscender", "=", "in", ".", "readTTFShort", "(", ")", ";", "log", ".", "debug", "(", "\"hhea.Ascender: \"", "+", "hheaAscender", "+", "\" \"", "+", "(", "hheaAscender", ")", ")", ";", "hheaDescender", "=", "in", ".", "readTTFShort", "(", ")", ";", "log", ".", "debug", "(", "\"hhea.Descender: \"", "+", "hheaDescender", "+", "\" \"", "+", "(", "hheaDescender", ")", ")", ";", "in", ".", "skip", "(", "2", "+", "2", "+", "3", "*", "2", "+", "8", "*", "2", ")", ";", "nhmtx", "=", "in", ".", "readTTFUShort", "(", ")", ";", "log", ".", "debug", "(", "\"Number of horizontal metrics: \"", "+", "nhmtx", ")", ";", "}" ]
Read the "hhea" table to find the ascender and descender and size of "hmtx" table, as a fixed size font might have only one width. @param in FontFileReader to read the hhea table from @throws IOException in case of an I/O problem
[ "Read", "the", "hhea", "table", "to", "find", "the", "ascender", "and", "descender", "and", "size", "of", "hmtx", "table", "as", "a", "fixed", "size", "font", "might", "have", "only", "one", "width", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L850-L863
1,718
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.readPostScript
private final void readPostScript(FontFileReader in) throws IOException { seekTab(in, "post", 0); postFormat = in.readTTFLong(); italicAngle = in.readTTFULong(); underlinePosition = in.readTTFShort(); underlineThickness = in.readTTFShort(); isFixedPitch = in.readTTFULong(); //Skip memory usage values in.skip(4 * 4); log.debug("PostScript format: 0x" + Integer.toHexString(postFormat)); switch (postFormat) { case 0x00010000: log.debug("PostScript format 1"); for (int i = 0; i < Glyphs.MAC_GLYPH_NAMES.length; i++) { mtxTab[i].setName(Glyphs.MAC_GLYPH_NAMES[i]); } break; case 0x00020000: log.debug("PostScript format 2"); int numGlyphStrings = 0; // Read Number of Glyphs int l = in.readTTFUShort(); // Read indexes for (int i = 0; i < l; i++) { mtxTab[i].setIndex(in.readTTFUShort()); if (mtxTab[i].getIndex() > 257) { //Index is not in the Macintosh standard set numGlyphStrings++; } if (log.isTraceEnabled()) { log.trace("PostScript index: " + mtxTab[i].getIndexAsString()); } } // firstChar=minIndex; String[] psGlyphsBuffer = new String[numGlyphStrings]; if (log.isDebugEnabled()) { log.debug("Reading " + numGlyphStrings + " glyphnames, that are not in the standard Macintosh" + " set. Total number of glyphs=" + l); } for (int i = 0; i < psGlyphsBuffer.length; i++) { psGlyphsBuffer[i] = in.readTTFString(in.readTTFUByte()); } //Set glyph names for (int i = 0; i < l; i++) { if (mtxTab[i].getIndex() < NMACGLYPHS) { mtxTab[i].setName(Glyphs.MAC_GLYPH_NAMES[mtxTab[i].getIndex()]); } else { if (!mtxTab[i].isIndexReserved()) { int k = mtxTab[i].getIndex() - NMACGLYPHS; if (log.isTraceEnabled()) { log.trace(k + " i=" + i + " mtx=" + mtxTab.length + " ps=" + psGlyphsBuffer.length); } mtxTab[i].setName(psGlyphsBuffer[k]); } } } break; case 0x00030000: // PostScript format 3 contains no glyph names log.debug("PostScript format 3"); break; default: log.error("Unknown PostScript format: " + postFormat); } }
java
private final void readPostScript(FontFileReader in) throws IOException { seekTab(in, "post", 0); postFormat = in.readTTFLong(); italicAngle = in.readTTFULong(); underlinePosition = in.readTTFShort(); underlineThickness = in.readTTFShort(); isFixedPitch = in.readTTFULong(); //Skip memory usage values in.skip(4 * 4); log.debug("PostScript format: 0x" + Integer.toHexString(postFormat)); switch (postFormat) { case 0x00010000: log.debug("PostScript format 1"); for (int i = 0; i < Glyphs.MAC_GLYPH_NAMES.length; i++) { mtxTab[i].setName(Glyphs.MAC_GLYPH_NAMES[i]); } break; case 0x00020000: log.debug("PostScript format 2"); int numGlyphStrings = 0; // Read Number of Glyphs int l = in.readTTFUShort(); // Read indexes for (int i = 0; i < l; i++) { mtxTab[i].setIndex(in.readTTFUShort()); if (mtxTab[i].getIndex() > 257) { //Index is not in the Macintosh standard set numGlyphStrings++; } if (log.isTraceEnabled()) { log.trace("PostScript index: " + mtxTab[i].getIndexAsString()); } } // firstChar=minIndex; String[] psGlyphsBuffer = new String[numGlyphStrings]; if (log.isDebugEnabled()) { log.debug("Reading " + numGlyphStrings + " glyphnames, that are not in the standard Macintosh" + " set. Total number of glyphs=" + l); } for (int i = 0; i < psGlyphsBuffer.length; i++) { psGlyphsBuffer[i] = in.readTTFString(in.readTTFUByte()); } //Set glyph names for (int i = 0; i < l; i++) { if (mtxTab[i].getIndex() < NMACGLYPHS) { mtxTab[i].setName(Glyphs.MAC_GLYPH_NAMES[mtxTab[i].getIndex()]); } else { if (!mtxTab[i].isIndexReserved()) { int k = mtxTab[i].getIndex() - NMACGLYPHS; if (log.isTraceEnabled()) { log.trace(k + " i=" + i + " mtx=" + mtxTab.length + " ps=" + psGlyphsBuffer.length); } mtxTab[i].setName(psGlyphsBuffer[k]); } } } break; case 0x00030000: // PostScript format 3 contains no glyph names log.debug("PostScript format 3"); break; default: log.error("Unknown PostScript format: " + postFormat); } }
[ "private", "final", "void", "readPostScript", "(", "FontFileReader", "in", ")", "throws", "IOException", "{", "seekTab", "(", "in", ",", "\"post\"", ",", "0", ")", ";", "postFormat", "=", "in", ".", "readTTFLong", "(", ")", ";", "italicAngle", "=", "in", ".", "readTTFULong", "(", ")", ";", "underlinePosition", "=", "in", ".", "readTTFShort", "(", ")", ";", "underlineThickness", "=", "in", ".", "readTTFShort", "(", ")", ";", "isFixedPitch", "=", "in", ".", "readTTFULong", "(", ")", ";", "//Skip memory usage values", "in", ".", "skip", "(", "4", "*", "4", ")", ";", "log", ".", "debug", "(", "\"PostScript format: 0x\"", "+", "Integer", ".", "toHexString", "(", "postFormat", ")", ")", ";", "switch", "(", "postFormat", ")", "{", "case", "0x00010000", ":", "log", ".", "debug", "(", "\"PostScript format 1\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "Glyphs", ".", "MAC_GLYPH_NAMES", ".", "length", ";", "i", "++", ")", "{", "mtxTab", "[", "i", "]", ".", "setName", "(", "Glyphs", ".", "MAC_GLYPH_NAMES", "[", "i", "]", ")", ";", "}", "break", ";", "case", "0x00020000", ":", "log", ".", "debug", "(", "\"PostScript format 2\"", ")", ";", "int", "numGlyphStrings", "=", "0", ";", "// Read Number of Glyphs", "int", "l", "=", "in", ".", "readTTFUShort", "(", ")", ";", "// Read indexes", "for", "(", "int", "i", "=", "0", ";", "i", "<", "l", ";", "i", "++", ")", "{", "mtxTab", "[", "i", "]", ".", "setIndex", "(", "in", ".", "readTTFUShort", "(", ")", ")", ";", "if", "(", "mtxTab", "[", "i", "]", ".", "getIndex", "(", ")", ">", "257", ")", "{", "//Index is not in the Macintosh standard set", "numGlyphStrings", "++", ";", "}", "if", "(", "log", ".", "isTraceEnabled", "(", ")", ")", "{", "log", ".", "trace", "(", "\"PostScript index: \"", "+", "mtxTab", "[", "i", "]", ".", "getIndexAsString", "(", ")", ")", ";", "}", "}", "// firstChar=minIndex;", "String", "[", "]", "psGlyphsBuffer", "=", "new", "String", "[", "numGlyphStrings", "]", ";", "if", "(", "log", ".", "isDebugEnabled", "(", ")", ")", "{", "log", ".", "debug", "(", "\"Reading \"", "+", "numGlyphStrings", "+", "\" glyphnames, that are not in the standard Macintosh\"", "+", "\" set. Total number of glyphs=\"", "+", "l", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "psGlyphsBuffer", ".", "length", ";", "i", "++", ")", "{", "psGlyphsBuffer", "[", "i", "]", "=", "in", ".", "readTTFString", "(", "in", ".", "readTTFUByte", "(", ")", ")", ";", "}", "//Set glyph names", "for", "(", "int", "i", "=", "0", ";", "i", "<", "l", ";", "i", "++", ")", "{", "if", "(", "mtxTab", "[", "i", "]", ".", "getIndex", "(", ")", "<", "NMACGLYPHS", ")", "{", "mtxTab", "[", "i", "]", ".", "setName", "(", "Glyphs", ".", "MAC_GLYPH_NAMES", "[", "mtxTab", "[", "i", "]", ".", "getIndex", "(", ")", "]", ")", ";", "}", "else", "{", "if", "(", "!", "mtxTab", "[", "i", "]", ".", "isIndexReserved", "(", ")", ")", "{", "int", "k", "=", "mtxTab", "[", "i", "]", ".", "getIndex", "(", ")", "-", "NMACGLYPHS", ";", "if", "(", "log", ".", "isTraceEnabled", "(", ")", ")", "{", "log", ".", "trace", "(", "k", "+", "\" i=\"", "+", "i", "+", "\" mtx=\"", "+", "mtxTab", ".", "length", "+", "\" ps=\"", "+", "psGlyphsBuffer", ".", "length", ")", ";", "}", "mtxTab", "[", "i", "]", ".", "setName", "(", "psGlyphsBuffer", "[", "k", "]", ")", ";", "}", "}", "}", "break", ";", "case", "0x00030000", ":", "// PostScript format 3 contains no glyph names", "log", ".", "debug", "(", "\"PostScript format 3\"", ")", ";", "break", ";", "default", ":", "log", ".", "error", "(", "\"Unknown PostScript format: \"", "+", "postFormat", ")", ";", "}", "}" ]
Read the "post" table containing the PostScript names of the glyphs. @param in The reader to get the names from @throws IOException Indicates a failure to read the table
[ "Read", "the", "post", "table", "containing", "the", "PostScript", "names", "of", "the", "glyphs", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L916-L993
1,719
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.readIndexToLocation
protected final void readIndexToLocation(FontFileReader in) throws IOException { if (!seekTab(in, "loca", 0)) { throw new IOException("'loca' table not found, happens when the font file doesn't" + " contain TrueType outlines (trying to read an OpenType CFF font maybe?)"); } for (int i = 0; i < numberOfGlyphs; i++) { mtxTab[i].setOffset(locaFormat == 1 ? in.readTTFULong() : (in.readTTFUShort() << 1)); } lastLoca = (locaFormat == 1 ? in.readTTFULong() : (in.readTTFUShort() << 1)); }
java
protected final void readIndexToLocation(FontFileReader in) throws IOException { if (!seekTab(in, "loca", 0)) { throw new IOException("'loca' table not found, happens when the font file doesn't" + " contain TrueType outlines (trying to read an OpenType CFF font maybe?)"); } for (int i = 0; i < numberOfGlyphs; i++) { mtxTab[i].setOffset(locaFormat == 1 ? in.readTTFULong() : (in.readTTFUShort() << 1)); } lastLoca = (locaFormat == 1 ? in.readTTFULong() : (in.readTTFUShort() << 1)); }
[ "protected", "final", "void", "readIndexToLocation", "(", "FontFileReader", "in", ")", "throws", "IOException", "{", "if", "(", "!", "seekTab", "(", "in", ",", "\"loca\"", ",", "0", ")", ")", "{", "throw", "new", "IOException", "(", "\"'loca' table not found, happens when the font file doesn't\"", "+", "\" contain TrueType outlines (trying to read an OpenType CFF font maybe?)\"", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numberOfGlyphs", ";", "i", "++", ")", "{", "mtxTab", "[", "i", "]", ".", "setOffset", "(", "locaFormat", "==", "1", "?", "in", ".", "readTTFULong", "(", ")", ":", "(", "in", ".", "readTTFUShort", "(", ")", "<<", "1", ")", ")", ";", "}", "lastLoca", "=", "(", "locaFormat", "==", "1", "?", "in", ".", "readTTFULong", "(", ")", ":", "(", "in", ".", "readTTFUShort", "(", ")", "<<", "1", ")", ")", ";", "}" ]
Read the "loca" table. @param in FontFileReader to read from @throws IOException In case of a I/O problem
[ "Read", "the", "loca", "table", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L1046-L1058
1,720
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.readGlyf
private final void readGlyf(FontFileReader in) throws IOException { TTFDirTabEntry dirTab = (TTFDirTabEntry)dirTabs.get("glyf"); if (dirTab == null) { throw new IOException("glyf table not found, cannot continue"); } for (int i = 0; i < (numberOfGlyphs - 1); i++) { if (mtxTab[i].getOffset() != mtxTab[i + 1].getOffset()) { in.seekSet(dirTab.getOffset() + mtxTab[i].getOffset()); in.skip(2); final int[] bbox = { in.readTTFShort(), in.readTTFShort(), in.readTTFShort(), in.readTTFShort()}; mtxTab[i].setBoundingBox(bbox); } else { mtxTab[i].setBoundingBox(mtxTab[0].getBoundingBox()); } } long n = ((TTFDirTabEntry)dirTabs.get("glyf")).getOffset(); for (int i = 0; i < numberOfGlyphs; i++) { if ((i + 1) >= mtxTab.length || mtxTab[i].getOffset() != mtxTab[i + 1].getOffset()) { in.seekSet(n + mtxTab[i].getOffset()); in.skip(2); final int[] bbox = { in.readTTFShort(), in.readTTFShort(), in.readTTFShort(), in.readTTFShort()}; mtxTab[i].setBoundingBox(bbox); } else { /**@todo Verify that this is correct, looks like a copy/paste bug (jm)*/ final int bbox0 = mtxTab[0].getBoundingBox()[0]; final int[] bbox = {bbox0, bbox0, bbox0, bbox0}; mtxTab[i].setBoundingBox(bbox); /* Original code mtxTab[i].bbox[0] = mtxTab[0].bbox[0]; mtxTab[i].bbox[1] = mtxTab[0].bbox[0]; mtxTab[i].bbox[2] = mtxTab[0].bbox[0]; mtxTab[i].bbox[3] = mtxTab[0].bbox[0]; */ } if (log.isTraceEnabled()) { log.trace(mtxTab[i].toString(this)); } } }
java
private final void readGlyf(FontFileReader in) throws IOException { TTFDirTabEntry dirTab = (TTFDirTabEntry)dirTabs.get("glyf"); if (dirTab == null) { throw new IOException("glyf table not found, cannot continue"); } for (int i = 0; i < (numberOfGlyphs - 1); i++) { if (mtxTab[i].getOffset() != mtxTab[i + 1].getOffset()) { in.seekSet(dirTab.getOffset() + mtxTab[i].getOffset()); in.skip(2); final int[] bbox = { in.readTTFShort(), in.readTTFShort(), in.readTTFShort(), in.readTTFShort()}; mtxTab[i].setBoundingBox(bbox); } else { mtxTab[i].setBoundingBox(mtxTab[0].getBoundingBox()); } } long n = ((TTFDirTabEntry)dirTabs.get("glyf")).getOffset(); for (int i = 0; i < numberOfGlyphs; i++) { if ((i + 1) >= mtxTab.length || mtxTab[i].getOffset() != mtxTab[i + 1].getOffset()) { in.seekSet(n + mtxTab[i].getOffset()); in.skip(2); final int[] bbox = { in.readTTFShort(), in.readTTFShort(), in.readTTFShort(), in.readTTFShort()}; mtxTab[i].setBoundingBox(bbox); } else { /**@todo Verify that this is correct, looks like a copy/paste bug (jm)*/ final int bbox0 = mtxTab[0].getBoundingBox()[0]; final int[] bbox = {bbox0, bbox0, bbox0, bbox0}; mtxTab[i].setBoundingBox(bbox); /* Original code mtxTab[i].bbox[0] = mtxTab[0].bbox[0]; mtxTab[i].bbox[1] = mtxTab[0].bbox[0]; mtxTab[i].bbox[2] = mtxTab[0].bbox[0]; mtxTab[i].bbox[3] = mtxTab[0].bbox[0]; */ } if (log.isTraceEnabled()) { log.trace(mtxTab[i].toString(this)); } } }
[ "private", "final", "void", "readGlyf", "(", "FontFileReader", "in", ")", "throws", "IOException", "{", "TTFDirTabEntry", "dirTab", "=", "(", "TTFDirTabEntry", ")", "dirTabs", ".", "get", "(", "\"glyf\"", ")", ";", "if", "(", "dirTab", "==", "null", ")", "{", "throw", "new", "IOException", "(", "\"glyf table not found, cannot continue\"", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "(", "numberOfGlyphs", "-", "1", ")", ";", "i", "++", ")", "{", "if", "(", "mtxTab", "[", "i", "]", ".", "getOffset", "(", ")", "!=", "mtxTab", "[", "i", "+", "1", "]", ".", "getOffset", "(", ")", ")", "{", "in", ".", "seekSet", "(", "dirTab", ".", "getOffset", "(", ")", "+", "mtxTab", "[", "i", "]", ".", "getOffset", "(", ")", ")", ";", "in", ".", "skip", "(", "2", ")", ";", "final", "int", "[", "]", "bbox", "=", "{", "in", ".", "readTTFShort", "(", ")", ",", "in", ".", "readTTFShort", "(", ")", ",", "in", ".", "readTTFShort", "(", ")", ",", "in", ".", "readTTFShort", "(", ")", "}", ";", "mtxTab", "[", "i", "]", ".", "setBoundingBox", "(", "bbox", ")", ";", "}", "else", "{", "mtxTab", "[", "i", "]", ".", "setBoundingBox", "(", "mtxTab", "[", "0", "]", ".", "getBoundingBox", "(", ")", ")", ";", "}", "}", "long", "n", "=", "(", "(", "TTFDirTabEntry", ")", "dirTabs", ".", "get", "(", "\"glyf\"", ")", ")", ".", "getOffset", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numberOfGlyphs", ";", "i", "++", ")", "{", "if", "(", "(", "i", "+", "1", ")", ">=", "mtxTab", ".", "length", "||", "mtxTab", "[", "i", "]", ".", "getOffset", "(", ")", "!=", "mtxTab", "[", "i", "+", "1", "]", ".", "getOffset", "(", ")", ")", "{", "in", ".", "seekSet", "(", "n", "+", "mtxTab", "[", "i", "]", ".", "getOffset", "(", ")", ")", ";", "in", ".", "skip", "(", "2", ")", ";", "final", "int", "[", "]", "bbox", "=", "{", "in", ".", "readTTFShort", "(", ")", ",", "in", ".", "readTTFShort", "(", ")", ",", "in", ".", "readTTFShort", "(", ")", ",", "in", ".", "readTTFShort", "(", ")", "}", ";", "mtxTab", "[", "i", "]", ".", "setBoundingBox", "(", "bbox", ")", ";", "}", "else", "{", "/**@todo Verify that this is correct, looks like a copy/paste bug (jm)*/", "final", "int", "bbox0", "=", "mtxTab", "[", "0", "]", ".", "getBoundingBox", "(", ")", "[", "0", "]", ";", "final", "int", "[", "]", "bbox", "=", "{", "bbox0", ",", "bbox0", ",", "bbox0", ",", "bbox0", "}", ";", "mtxTab", "[", "i", "]", ".", "setBoundingBox", "(", "bbox", ")", ";", "/* Original code\n mtxTab[i].bbox[0] = mtxTab[0].bbox[0];\n mtxTab[i].bbox[1] = mtxTab[0].bbox[0];\n mtxTab[i].bbox[2] = mtxTab[0].bbox[0];\n mtxTab[i].bbox[3] = mtxTab[0].bbox[0]; */", "}", "if", "(", "log", ".", "isTraceEnabled", "(", ")", ")", "{", "log", ".", "trace", "(", "mtxTab", "[", "i", "]", ".", "toString", "(", "this", ")", ")", ";", "}", "}", "}" ]
Read the "glyf" table to find the bounding boxes. @param in FontFileReader to read from @throws IOException In case of a I/O problem
[ "Read", "the", "glyf", "table", "to", "find", "the", "bounding", "boxes", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L1065-L1113
1,721
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.readName
private final void readName(FontFileReader in) throws IOException { seekTab(in, "name", 2); int i = in.getCurrentPos(); int n = in.readTTFUShort(); int j = in.readTTFUShort() + i - 2; i += 2 * 2; while (n-- > 0) { // getLogger().debug("Iteration: " + n); in.seekSet(i); final int platformID = in.readTTFUShort(); final int encodingID = in.readTTFUShort(); final int languageID = in.readTTFUShort(); int k = in.readTTFUShort(); int l = in.readTTFUShort(); if (((platformID == 1 || platformID == 3) && (encodingID == 0 || encodingID == 1)) && (k == 1 || k == 2 || k == 0 || k == 4 || k == 6)) { in.seekSet(j + in.readTTFUShort()); String txt = in.readTTFString(l); log.debug(platformID + " " + encodingID + " " + languageID + " " + k + " " + txt); switch (k) { case 0: notice = txt; break; case 1: familyName = txt; break; case 2: subFamilyName = txt; break; case 4: fullName = txt; break; case 6: fontName = txt; break; } if (!notice.equals("") && !fullName.equals("") && !fontName.equals("") && !familyName.equals("") && !subFamilyName.equals("")) { break; } } i += 6 * 2; } }
java
private final void readName(FontFileReader in) throws IOException { seekTab(in, "name", 2); int i = in.getCurrentPos(); int n = in.readTTFUShort(); int j = in.readTTFUShort() + i - 2; i += 2 * 2; while (n-- > 0) { // getLogger().debug("Iteration: " + n); in.seekSet(i); final int platformID = in.readTTFUShort(); final int encodingID = in.readTTFUShort(); final int languageID = in.readTTFUShort(); int k = in.readTTFUShort(); int l = in.readTTFUShort(); if (((platformID == 1 || platformID == 3) && (encodingID == 0 || encodingID == 1)) && (k == 1 || k == 2 || k == 0 || k == 4 || k == 6)) { in.seekSet(j + in.readTTFUShort()); String txt = in.readTTFString(l); log.debug(platformID + " " + encodingID + " " + languageID + " " + k + " " + txt); switch (k) { case 0: notice = txt; break; case 1: familyName = txt; break; case 2: subFamilyName = txt; break; case 4: fullName = txt; break; case 6: fontName = txt; break; } if (!notice.equals("") && !fullName.equals("") && !fontName.equals("") && !familyName.equals("") && !subFamilyName.equals("")) { break; } } i += 6 * 2; } }
[ "private", "final", "void", "readName", "(", "FontFileReader", "in", ")", "throws", "IOException", "{", "seekTab", "(", "in", ",", "\"name\"", ",", "2", ")", ";", "int", "i", "=", "in", ".", "getCurrentPos", "(", ")", ";", "int", "n", "=", "in", ".", "readTTFUShort", "(", ")", ";", "int", "j", "=", "in", ".", "readTTFUShort", "(", ")", "+", "i", "-", "2", ";", "i", "+=", "2", "*", "2", ";", "while", "(", "n", "--", ">", "0", ")", "{", "// getLogger().debug(\"Iteration: \" + n);", "in", ".", "seekSet", "(", "i", ")", ";", "final", "int", "platformID", "=", "in", ".", "readTTFUShort", "(", ")", ";", "final", "int", "encodingID", "=", "in", ".", "readTTFUShort", "(", ")", ";", "final", "int", "languageID", "=", "in", ".", "readTTFUShort", "(", ")", ";", "int", "k", "=", "in", ".", "readTTFUShort", "(", ")", ";", "int", "l", "=", "in", ".", "readTTFUShort", "(", ")", ";", "if", "(", "(", "(", "platformID", "==", "1", "||", "platformID", "==", "3", ")", "&&", "(", "encodingID", "==", "0", "||", "encodingID", "==", "1", ")", ")", "&&", "(", "k", "==", "1", "||", "k", "==", "2", "||", "k", "==", "0", "||", "k", "==", "4", "||", "k", "==", "6", ")", ")", "{", "in", ".", "seekSet", "(", "j", "+", "in", ".", "readTTFUShort", "(", ")", ")", ";", "String", "txt", "=", "in", ".", "readTTFString", "(", "l", ")", ";", "log", ".", "debug", "(", "platformID", "+", "\" \"", "+", "encodingID", "+", "\" \"", "+", "languageID", "+", "\" \"", "+", "k", "+", "\" \"", "+", "txt", ")", ";", "switch", "(", "k", ")", "{", "case", "0", ":", "notice", "=", "txt", ";", "break", ";", "case", "1", ":", "familyName", "=", "txt", ";", "break", ";", "case", "2", ":", "subFamilyName", "=", "txt", ";", "break", ";", "case", "4", ":", "fullName", "=", "txt", ";", "break", ";", "case", "6", ":", "fontName", "=", "txt", ";", "break", ";", "}", "if", "(", "!", "notice", ".", "equals", "(", "\"\"", ")", "&&", "!", "fullName", ".", "equals", "(", "\"\"", ")", "&&", "!", "fontName", ".", "equals", "(", "\"\"", ")", "&&", "!", "familyName", ".", "equals", "(", "\"\"", ")", "&&", "!", "subFamilyName", ".", "equals", "(", "\"\"", ")", ")", "{", "break", ";", "}", "}", "i", "+=", "6", "*", "2", ";", "}", "}" ]
Read the "name" table. @param in FontFileReader to read from @throws IOException In case of a I/O problem
[ "Read", "the", "name", "table", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L1120-L1174
1,722
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.readPCLT
private final boolean readPCLT(FontFileReader in) throws IOException { TTFDirTabEntry dirTab = (TTFDirTabEntry)dirTabs.get("PCLT"); if (dirTab != null) { in.seekSet(dirTab.getOffset() + 4 + 4 + 2); xHeight = in.readTTFUShort(); log.debug("xHeight from PCLT: " + xHeight + " " + (xHeight)); in.skip(2 * 2); capHeight = in.readTTFUShort(); log.debug("capHeight from PCLT: " + capHeight + " " + (capHeight)); in.skip(2 + 16 + 8 + 6 + 1 + 1); int serifStyle = in.readTTFUByte(); serifStyle = serifStyle >> 6; serifStyle = serifStyle & 3; if (serifStyle == 1) { hasSerifs = false; } else { hasSerifs = true; } return true; } else { return false; } }
java
private final boolean readPCLT(FontFileReader in) throws IOException { TTFDirTabEntry dirTab = (TTFDirTabEntry)dirTabs.get("PCLT"); if (dirTab != null) { in.seekSet(dirTab.getOffset() + 4 + 4 + 2); xHeight = in.readTTFUShort(); log.debug("xHeight from PCLT: " + xHeight + " " + (xHeight)); in.skip(2 * 2); capHeight = in.readTTFUShort(); log.debug("capHeight from PCLT: " + capHeight + " " + (capHeight)); in.skip(2 + 16 + 8 + 6 + 1 + 1); int serifStyle = in.readTTFUByte(); serifStyle = serifStyle >> 6; serifStyle = serifStyle & 3; if (serifStyle == 1) { hasSerifs = false; } else { hasSerifs = true; } return true; } else { return false; } }
[ "private", "final", "boolean", "readPCLT", "(", "FontFileReader", "in", ")", "throws", "IOException", "{", "TTFDirTabEntry", "dirTab", "=", "(", "TTFDirTabEntry", ")", "dirTabs", ".", "get", "(", "\"PCLT\"", ")", ";", "if", "(", "dirTab", "!=", "null", ")", "{", "in", ".", "seekSet", "(", "dirTab", ".", "getOffset", "(", ")", "+", "4", "+", "4", "+", "2", ")", ";", "xHeight", "=", "in", ".", "readTTFUShort", "(", ")", ";", "log", ".", "debug", "(", "\"xHeight from PCLT: \"", "+", "xHeight", "+", "\" \"", "+", "(", "xHeight", ")", ")", ";", "in", ".", "skip", "(", "2", "*", "2", ")", ";", "capHeight", "=", "in", ".", "readTTFUShort", "(", ")", ";", "log", ".", "debug", "(", "\"capHeight from PCLT: \"", "+", "capHeight", "+", "\" \"", "+", "(", "capHeight", ")", ")", ";", "in", ".", "skip", "(", "2", "+", "16", "+", "8", "+", "6", "+", "1", "+", "1", ")", ";", "int", "serifStyle", "=", "in", ".", "readTTFUByte", "(", ")", ";", "serifStyle", "=", "serifStyle", ">>", "6", ";", "serifStyle", "=", "serifStyle", "&", "3", ";", "if", "(", "serifStyle", "==", "1", ")", "{", "hasSerifs", "=", "false", ";", "}", "else", "{", "hasSerifs", "=", "true", ";", "}", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Read the "PCLT" table to find xHeight and capHeight. @param in The reader to get the table from @return True if the table has been read @throws IOException Indicates a failure to read the table
[ "Read", "the", "PCLT", "table", "to", "find", "xHeight", "and", "capHeight", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L1183-L1208
1,723
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.checkTTC
protected final boolean checkTTC(FontFileReader in, String name) throws IOException { String tag = in.readTTFString(4); if ("ttcf".equals(tag)) { // This is a TrueType Collection in.skip(4); // Read directory offsets int numDirectories = (int)in.readTTFULong(); // int numDirectories=in.readTTFUShort(); long[] dirOffsets = new long[numDirectories]; for (int i = 0; i < numDirectories; i++) { dirOffsets[i] = in.readTTFULong(); } log.info("This is a TrueType collection file with " + numDirectories + " fonts"); log.info("Containing the following fonts: "); // Read all the directories and name tables to check // If the font exists - this is a bit ugly, but... boolean found = false; // Iterate through all name tables even if font // Is found, just to show all the names long dirTabOffset = 0; for (int i = 0; (i < numDirectories); i++) { in.seekSet(dirOffsets[i]); readDirTabs(in); readName(in); if (fullName.equals(name)) { found = true; dirTabOffset = dirOffsets[i]; log.info(fullName + " <-- selected"); } else { log.info(fullName); } // Reset names notice = ""; fullName = ""; familyName = ""; fontName = ""; subFamilyName = ""; } in.seekSet(dirTabOffset); return found; } else { in.seekSet(0); return true; } }
java
protected final boolean checkTTC(FontFileReader in, String name) throws IOException { String tag = in.readTTFString(4); if ("ttcf".equals(tag)) { // This is a TrueType Collection in.skip(4); // Read directory offsets int numDirectories = (int)in.readTTFULong(); // int numDirectories=in.readTTFUShort(); long[] dirOffsets = new long[numDirectories]; for (int i = 0; i < numDirectories; i++) { dirOffsets[i] = in.readTTFULong(); } log.info("This is a TrueType collection file with " + numDirectories + " fonts"); log.info("Containing the following fonts: "); // Read all the directories and name tables to check // If the font exists - this is a bit ugly, but... boolean found = false; // Iterate through all name tables even if font // Is found, just to show all the names long dirTabOffset = 0; for (int i = 0; (i < numDirectories); i++) { in.seekSet(dirOffsets[i]); readDirTabs(in); readName(in); if (fullName.equals(name)) { found = true; dirTabOffset = dirOffsets[i]; log.info(fullName + " <-- selected"); } else { log.info(fullName); } // Reset names notice = ""; fullName = ""; familyName = ""; fontName = ""; subFamilyName = ""; } in.seekSet(dirTabOffset); return found; } else { in.seekSet(0); return true; } }
[ "protected", "final", "boolean", "checkTTC", "(", "FontFileReader", "in", ",", "String", "name", ")", "throws", "IOException", "{", "String", "tag", "=", "in", ".", "readTTFString", "(", "4", ")", ";", "if", "(", "\"ttcf\"", ".", "equals", "(", "tag", ")", ")", "{", "// This is a TrueType Collection", "in", ".", "skip", "(", "4", ")", ";", "// Read directory offsets", "int", "numDirectories", "=", "(", "int", ")", "in", ".", "readTTFULong", "(", ")", ";", "// int numDirectories=in.readTTFUShort();", "long", "[", "]", "dirOffsets", "=", "new", "long", "[", "numDirectories", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numDirectories", ";", "i", "++", ")", "{", "dirOffsets", "[", "i", "]", "=", "in", ".", "readTTFULong", "(", ")", ";", "}", "log", ".", "info", "(", "\"This is a TrueType collection file with \"", "+", "numDirectories", "+", "\" fonts\"", ")", ";", "log", ".", "info", "(", "\"Containing the following fonts: \"", ")", ";", "// Read all the directories and name tables to check", "// If the font exists - this is a bit ugly, but...", "boolean", "found", "=", "false", ";", "// Iterate through all name tables even if font", "// Is found, just to show all the names", "long", "dirTabOffset", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "(", "i", "<", "numDirectories", ")", ";", "i", "++", ")", "{", "in", ".", "seekSet", "(", "dirOffsets", "[", "i", "]", ")", ";", "readDirTabs", "(", "in", ")", ";", "readName", "(", "in", ")", ";", "if", "(", "fullName", ".", "equals", "(", "name", ")", ")", "{", "found", "=", "true", ";", "dirTabOffset", "=", "dirOffsets", "[", "i", "]", ";", "log", ".", "info", "(", "fullName", "+", "\" <-- selected\"", ")", ";", "}", "else", "{", "log", ".", "info", "(", "fullName", ")", ";", "}", "// Reset names", "notice", "=", "\"\"", ";", "fullName", "=", "\"\"", ";", "familyName", "=", "\"\"", ";", "fontName", "=", "\"\"", ";", "subFamilyName", "=", "\"\"", ";", "}", "in", ".", "seekSet", "(", "dirTabOffset", ")", ";", "return", "found", ";", "}", "else", "{", "in", ".", "seekSet", "(", "0", ")", ";", "return", "true", ";", "}", "}" ]
Check if this is a TrueType collection and that the given name exists in the collection. If it does, set offset in fontfile to the beginning of the Table Directory for that font. @param in FontFileReader to read from @param name The name to check @return True if not collection or font name present, false otherwise @throws IOException In case of an I/O problem
[ "Check", "if", "this", "is", "a", "TrueType", "collection", "and", "that", "the", "given", "name", "exists", "in", "the", "collection", ".", "If", "it", "does", "set", "offset", "in", "fontfile", "to", "the", "beginning", "of", "the", "Table", "Directory", "for", "that", "font", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L1427-L1480
1,724
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.unicodeToWinAnsi
private Integer[] unicodeToWinAnsi(int unicode) { List ret = new java.util.ArrayList(); for (int i = 32; i < Glyphs.WINANSI_ENCODING.length; i++) { if (unicode == Glyphs.WINANSI_ENCODING[i]) { ret.add(new Integer(i)); } } return (Integer[])ret.toArray(new Integer[0]); }
java
private Integer[] unicodeToWinAnsi(int unicode) { List ret = new java.util.ArrayList(); for (int i = 32; i < Glyphs.WINANSI_ENCODING.length; i++) { if (unicode == Glyphs.WINANSI_ENCODING[i]) { ret.add(new Integer(i)); } } return (Integer[])ret.toArray(new Integer[0]); }
[ "private", "Integer", "[", "]", "unicodeToWinAnsi", "(", "int", "unicode", ")", "{", "List", "ret", "=", "new", "java", ".", "util", ".", "ArrayList", "(", ")", ";", "for", "(", "int", "i", "=", "32", ";", "i", "<", "Glyphs", ".", "WINANSI_ENCODING", ".", "length", ";", "i", "++", ")", "{", "if", "(", "unicode", "==", "Glyphs", ".", "WINANSI_ENCODING", "[", "i", "]", ")", "{", "ret", ".", "add", "(", "new", "Integer", "(", "i", ")", ")", ";", "}", "}", "return", "(", "Integer", "[", "]", ")", "ret", ".", "toArray", "(", "new", "Integer", "[", "0", "]", ")", ";", "}" ]
Helper methods, they are not very efficient, but that really doesn't matter... @param unicode The unicode character to convert @return The converted WinAnsi value
[ "Helper", "methods", "they", "are", "not", "very", "efficient", "but", "that", "really", "doesn", "t", "matter", "..." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L1489-L1497
1,725
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.printStuff
public void printStuff() { System.out.println("Font name: " + fontName); System.out.println("Full name: " + fullName); System.out.println("Family name: " + familyName); System.out.println("Subfamily name: " + subFamilyName); System.out.println("Notice: " + notice); System.out.println("xHeight: " + (xHeight)); System.out.println("capheight: " + (capHeight)); int italic = (int)(italicAngle >> 16); System.out.println("Italic: " + italic); System.out.print("ItalicAngle: " + (short)(italicAngle / 0x10000)); if ((italicAngle % 0x10000) > 0) { System.out.print("." + (short)((italicAngle % 0x10000) * 1000) / 0x10000); } System.out.println(); System.out.println("Ascender: " + (ascender)); System.out.println("Descender: " + (descender)); System.out.println("FontBBox: [" + (fontBBox1) + " " + (fontBBox2) + " " + (fontBBox3) + " " + (fontBBox4) + "]"); }
java
public void printStuff() { System.out.println("Font name: " + fontName); System.out.println("Full name: " + fullName); System.out.println("Family name: " + familyName); System.out.println("Subfamily name: " + subFamilyName); System.out.println("Notice: " + notice); System.out.println("xHeight: " + (xHeight)); System.out.println("capheight: " + (capHeight)); int italic = (int)(italicAngle >> 16); System.out.println("Italic: " + italic); System.out.print("ItalicAngle: " + (short)(italicAngle / 0x10000)); if ((italicAngle % 0x10000) > 0) { System.out.print("." + (short)((italicAngle % 0x10000) * 1000) / 0x10000); } System.out.println(); System.out.println("Ascender: " + (ascender)); System.out.println("Descender: " + (descender)); System.out.println("FontBBox: [" + (fontBBox1) + " " + (fontBBox2) + " " + (fontBBox3) + " " + (fontBBox4) + "]"); }
[ "public", "void", "printStuff", "(", ")", "{", "System", ".", "out", ".", "println", "(", "\"Font name: \"", "+", "fontName", ")", ";", "System", ".", "out", ".", "println", "(", "\"Full name: \"", "+", "fullName", ")", ";", "System", ".", "out", ".", "println", "(", "\"Family name: \"", "+", "familyName", ")", ";", "System", ".", "out", ".", "println", "(", "\"Subfamily name: \"", "+", "subFamilyName", ")", ";", "System", ".", "out", ".", "println", "(", "\"Notice: \"", "+", "notice", ")", ";", "System", ".", "out", ".", "println", "(", "\"xHeight: \"", "+", "(", "xHeight", ")", ")", ";", "System", ".", "out", ".", "println", "(", "\"capheight: \"", "+", "(", "capHeight", ")", ")", ";", "int", "italic", "=", "(", "int", ")", "(", "italicAngle", ">>", "16", ")", ";", "System", ".", "out", ".", "println", "(", "\"Italic: \"", "+", "italic", ")", ";", "System", ".", "out", ".", "print", "(", "\"ItalicAngle: \"", "+", "(", "short", ")", "(", "italicAngle", "/", "0x10000", ")", ")", ";", "if", "(", "(", "italicAngle", "%", "0x10000", ")", ">", "0", ")", "{", "System", ".", "out", ".", "print", "(", "\".\"", "+", "(", "short", ")", "(", "(", "italicAngle", "%", "0x10000", ")", "*", "1000", ")", "/", "0x10000", ")", ";", "}", "System", ".", "out", ".", "println", "(", ")", ";", "System", ".", "out", ".", "println", "(", "\"Ascender: \"", "+", "(", "ascender", ")", ")", ";", "System", ".", "out", ".", "println", "(", "\"Descender: \"", "+", "(", "descender", ")", ")", ";", "System", ".", "out", ".", "println", "(", "\"FontBBox: [\"", "+", "(", "fontBBox1", ")", "+", "\" \"", "+", "(", "fontBBox2", ")", "+", "\" \"", "+", "(", "fontBBox3", ")", "+", "\" \"", "+", "(", "fontBBox4", ")", "+", "\"]\"", ")", ";", "}" ]
Dumps a few informational values to System.out.
[ "Dumps", "a", "few", "informational", "values", "to", "System", ".", "out", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L1502-L1526
1,726
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.unicodeToGlyph
private Integer unicodeToGlyph(int unicodeIndex) throws IOException { final Integer result = (Integer) unicodeToGlyphMap.get(new Integer(unicodeIndex)); if (result == null) { throw new IOException( "Glyph index not found for unicode value " + unicodeIndex); } return result; }
java
private Integer unicodeToGlyph(int unicodeIndex) throws IOException { final Integer result = (Integer) unicodeToGlyphMap.get(new Integer(unicodeIndex)); if (result == null) { throw new IOException( "Glyph index not found for unicode value " + unicodeIndex); } return result; }
[ "private", "Integer", "unicodeToGlyph", "(", "int", "unicodeIndex", ")", "throws", "IOException", "{", "final", "Integer", "result", "=", "(", "Integer", ")", "unicodeToGlyphMap", ".", "get", "(", "new", "Integer", "(", "unicodeIndex", ")", ")", ";", "if", "(", "result", "==", "null", ")", "{", "throw", "new", "IOException", "(", "\"Glyph index not found for unicode value \"", "+", "unicodeIndex", ")", ";", "}", "return", "result", ";", "}" ]
Map a unicode code point to the corresponding glyph index @param unicodeIndex unicode code point @return glyph index @throws IOException if unicodeIndex not found
[ "Map", "a", "unicode", "code", "point", "to", "the", "corresponding", "glyph", "index" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L1546-L1554
1,727
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java
TTFFile.main
public static void main(String[] args) { try { TTFFile ttfFile = new TTFFile(); FontFileReader reader = new FontFileReader(args[0]); String name = null; if (args.length >= 2) { name = args[1]; } ttfFile.readFont(reader, name); ttfFile.printStuff(); } catch (IOException ioe) { System.err.println("Problem reading font: " + ioe.toString()); ioe.printStackTrace(System.err); } }
java
public static void main(String[] args) { try { TTFFile ttfFile = new TTFFile(); FontFileReader reader = new FontFileReader(args[0]); String name = null; if (args.length >= 2) { name = args[1]; } ttfFile.readFont(reader, name); ttfFile.printStuff(); } catch (IOException ioe) { System.err.println("Problem reading font: " + ioe.toString()); ioe.printStackTrace(System.err); } }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "{", "try", "{", "TTFFile", "ttfFile", "=", "new", "TTFFile", "(", ")", ";", "FontFileReader", "reader", "=", "new", "FontFileReader", "(", "args", "[", "0", "]", ")", ";", "String", "name", "=", "null", ";", "if", "(", "args", ".", "length", ">=", "2", ")", "{", "name", "=", "args", "[", "1", "]", ";", "}", "ttfFile", ".", "readFont", "(", "reader", ",", "name", ")", ";", "ttfFile", ".", "printStuff", "(", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "System", ".", "err", ".", "println", "(", "\"Problem reading font: \"", "+", "ioe", ".", "toString", "(", ")", ")", ";", "ioe", ".", "printStackTrace", "(", "System", ".", "err", ")", ";", "}", "}" ]
Static main method to get info about a TrueType font. @param args The command line arguments
[ "Static", "main", "method", "to", "get", "info", "about", "a", "TrueType", "font", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFFile.java#L1560-L1578
1,728
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/openal/OggDecoder.java
OggDecoder.getData
public OggData getData(InputStream input) throws IOException { if (input == null) { throw new IOException("Failed to read OGG, source does not exist?"); } ByteArrayOutputStream dataout = new ByteArrayOutputStream(); // SyncState oy = new SyncState(); // sync and verify incoming physical bitstream // StreamState os = new StreamState(); // take physical pages, weld into a logical stream of packets // Page og = new Page(); // one Ogg bitstream page. Vorbis packets are inside // Packet op = new Packet(); // one raw packet of data for decode // // Info vi = new Info(); // struct that stores all the static vorbis bitstream settings // Comment vc = new Comment(); // struct that stores all the bitstream user comments // DspState vd = new DspState(); // central working state for the packet->PCM decoder // Block vb = new Block(vd); // local working space for packet->PCM decode // // byte[] buffer; // int bytes = 0; // // boolean bigEndian = ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN); // // Decode setup // // oy.init(); // Now we can read pages // // while (true) { // we repeat if the bitstream is chained // int eos = 0; // // // grab some data at the head of the stream. We want the first page // // (which is guaranteed to be small and only contain the Vorbis // // stream initial header) We need the first page to get the stream // // serialno. // // // submit a 4k block to libvorbis' Ogg layer // int index = oy.buffer(4096); // // buffer = oy.data; // try { // bytes = input.read(buffer, index, 4096); // } catch (Exception e) { // Log.error("Failure reading in vorbis"); // Log.error(e); // System.exit(0); // } // oy.wrote(bytes); // // // Get the first page. // if (oy.pageout(og) != 1) { // // have we simply run out of data? If so, we're done. // if (bytes < 4096) // break; // // // error case. Must not be Vorbis data // Log.error("Input does not appear to be an Ogg bitstream."); // System.exit(0); // } // // // Get the serial number and set up the rest of decode. // // serialno first; use it to set up a logical stream // os.init(og.serialno()); // // // extract the initial header from the first page and verify that the // // Ogg bitstream is in fact Vorbis data // // // I handle the initial header first instead of just having the code // // read all three Vorbis headers at once because reading the initial // // header is an easy way to identify a Vorbis bitstream and it's // // useful to see that functionality seperated out. // // vi.init(); // vc.init(); // if (os.pagein(og) < 0) { // // error; stream version mismatch perhaps // Log.error("Error reading first page of Ogg bitstream data."); // System.exit(0); // } // // if (os.packetout(op) != 1) { // // no page? must not be vorbis // Log.error("Error reading initial header packet."); // System.exit(0); // } // // if (vi.synthesis_headerin(vc, op) < 0) { // // error case; not a vorbis header // Log.error("This Ogg bitstream does not contain Vorbis audio data."); // System.exit(0); // } // // // At this point, we're sure we're Vorbis. We've set up the logical // // (Ogg) bitstream decoder. Get the comment and codebook headers and // // set up the Vorbis decoder // // // The next two packets in order are the comment and codebook headers. // // They're likely large and may span multiple pages. Thus we reead // // and submit data until we get our two pacakets, watching that no // // pages are missing. If a page is missing, error out; losing a // // header page is the only place where missing data is fatal. */ // // int i = 0; // while (i < 2) { // while (i < 2) { // // int result = oy.pageout(og); // if (result == 0) // break; // Need more data // // Don't complain about missing or corrupt data yet. We'll // // catch it at the packet output phase // // if (result == 1) { // os.pagein(og); // we can ignore any errors here // // as they'll also become apparent // // at packetout // while (i < 2) { // result = os.packetout(op); // if (result == 0) // break; // if (result == -1) { // // Uh oh; data at some point was corrupted or missing! // // We can't tolerate that in a header. Die. // Log.error("Corrupt secondary header. Exiting."); // System.exit(0); // } // vi.synthesis_headerin(vc, op); // i++; // } // } // } // // no harm in not checking before adding more // index = oy.buffer(4096); // buffer = oy.data; // try { // bytes = input.read(buffer, index, 4096); // } catch (Exception e) { // Log.error("Failed to read Vorbis: "); // Log.error(e); // System.exit(0); // } // if (bytes == 0 && i < 2) { // Log.error("End of file before finding all Vorbis headers!"); // System.exit(0); // } // oy.wrote(bytes); // } // // convsize = 4096 / vi.channels; // // // OK, got and parsed all three headers. Initialize the Vorbis // // packet->PCM decoder. // vd.synthesis_init(vi); // central decode state // vb.init(vd); // local state for most of the decode // // so multiple block decodes can // // proceed in parallel. We could init // // multiple vorbis_block structures // // for vd here // // float[][][] _pcm = new float[1][][]; // int[] _index = new int[vi.channels]; // // The rest is just a straight decode loop until end of stream // while (eos == 0) { // while (eos == 0) { // // int result = oy.pageout(og); // if (result == 0) // break; // need more data // if (result == -1) { // missing or corrupt data at this page position // Log.error("Corrupt or missing data in bitstream; continuing..."); // } else { // os.pagein(og); // can safely ignore errors at // // this point // while (true) { // result = os.packetout(op); // // if (result == 0) // break; // need more data // if (result == -1) { // missing or corrupt data at this page position // // no reason to complain; already complained above // } else { // // we have a packet. Decode it // int samples; // if (vb.synthesis(op) == 0) { // test for success! // vd.synthesis_blockin(vb); // } // // // **pcm is a multichannel float vector. In stereo, for // // example, pcm[0] is left, and pcm[1] is right. samples is // // the size of each channel. Convert the float values // // (-1.<=range<=1.) to whatever PCM format and write it out // // while ((samples = vd.synthesis_pcmout(_pcm, // _index)) > 0) { // float[][] pcm = _pcm[0]; // //boolean clipflag = false; // int bout = (samples < convsize ? samples // : convsize); // // // convert floats to 16 bit signed ints (host order) and // // interleave // for (i = 0; i < vi.channels; i++) { // int ptr = i * 2; // //int ptr=i; // int mono = _index[i]; // for (int j = 0; j < bout; j++) { // int val = (int) (pcm[i][mono + j] * 32767.); // // short val=(short)(pcm[i][mono+j]*32767.); // // int val=(int)Math.round(pcm[i][mono+j]*32767.); // // might as well guard against clipping // if (val > 32767) { // val = 32767; // //clipflag = true; // } // if (val < -32768) { // val = -32768; // //clipflag = true; // } // if (val < 0) // val = val | 0x8000; // // if (bigEndian) { // convbuffer[ptr] = (byte) (val >>> 8); // convbuffer[ptr + 1] = (byte) (val); // } else { // convbuffer[ptr] = (byte) (val); // convbuffer[ptr + 1] = (byte) (val >>> 8); // } // ptr += 2 * (vi.channels); // } // } // // dataout.write(convbuffer, 0, 2 * vi.channels * bout); // // vd.synthesis_read(bout); // tell libvorbis how // // many samples we // // actually consumed // } // } // } // if (og.eos() != 0) // eos = 1; // } // } // if (eos == 0) { // index = oy.buffer(4096); // if (index >= 0) { // buffer = oy.data; // try { // bytes = input.read(buffer, index, 4096); // } catch (Exception e) { // Log.error("Failure during vorbis decoding"); // Log.error(e); // return null; // } // } else { // bytes = 0; // } // oy.wrote(bytes); // if (bytes == 0) // eos = 1; // } // } // // // clean up this logical bitstream; before exit we see if we're // // followed by another [chained] // // os.clear(); // // // ogg_page and ogg_packet structs always point to storage in // // libvorbis. They're never freed or manipulated directly // // vb.clear(); // vd.clear(); // vi.clear(); // must be called last // } // // // OK, clean up the framer // oy.clear(); // OggData ogg = new OggData(); // ogg.channels = vi.channels; // ogg.rate = vi.rate; OggInputStream oggInput = new OggInputStream(input); boolean done = false; while (!oggInput.atEnd()) { dataout.write(oggInput.read()); } OggData ogg = new OggData(); ogg.channels = oggInput.getChannels(); ogg.rate = oggInput.getRate(); byte[] data = dataout.toByteArray(); ogg.data = ByteBuffer.allocateDirect(data.length); ogg.data.put(data); ogg.data.rewind(); return ogg; }
java
public OggData getData(InputStream input) throws IOException { if (input == null) { throw new IOException("Failed to read OGG, source does not exist?"); } ByteArrayOutputStream dataout = new ByteArrayOutputStream(); // SyncState oy = new SyncState(); // sync and verify incoming physical bitstream // StreamState os = new StreamState(); // take physical pages, weld into a logical stream of packets // Page og = new Page(); // one Ogg bitstream page. Vorbis packets are inside // Packet op = new Packet(); // one raw packet of data for decode // // Info vi = new Info(); // struct that stores all the static vorbis bitstream settings // Comment vc = new Comment(); // struct that stores all the bitstream user comments // DspState vd = new DspState(); // central working state for the packet->PCM decoder // Block vb = new Block(vd); // local working space for packet->PCM decode // // byte[] buffer; // int bytes = 0; // // boolean bigEndian = ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN); // // Decode setup // // oy.init(); // Now we can read pages // // while (true) { // we repeat if the bitstream is chained // int eos = 0; // // // grab some data at the head of the stream. We want the first page // // (which is guaranteed to be small and only contain the Vorbis // // stream initial header) We need the first page to get the stream // // serialno. // // // submit a 4k block to libvorbis' Ogg layer // int index = oy.buffer(4096); // // buffer = oy.data; // try { // bytes = input.read(buffer, index, 4096); // } catch (Exception e) { // Log.error("Failure reading in vorbis"); // Log.error(e); // System.exit(0); // } // oy.wrote(bytes); // // // Get the first page. // if (oy.pageout(og) != 1) { // // have we simply run out of data? If so, we're done. // if (bytes < 4096) // break; // // // error case. Must not be Vorbis data // Log.error("Input does not appear to be an Ogg bitstream."); // System.exit(0); // } // // // Get the serial number and set up the rest of decode. // // serialno first; use it to set up a logical stream // os.init(og.serialno()); // // // extract the initial header from the first page and verify that the // // Ogg bitstream is in fact Vorbis data // // // I handle the initial header first instead of just having the code // // read all three Vorbis headers at once because reading the initial // // header is an easy way to identify a Vorbis bitstream and it's // // useful to see that functionality seperated out. // // vi.init(); // vc.init(); // if (os.pagein(og) < 0) { // // error; stream version mismatch perhaps // Log.error("Error reading first page of Ogg bitstream data."); // System.exit(0); // } // // if (os.packetout(op) != 1) { // // no page? must not be vorbis // Log.error("Error reading initial header packet."); // System.exit(0); // } // // if (vi.synthesis_headerin(vc, op) < 0) { // // error case; not a vorbis header // Log.error("This Ogg bitstream does not contain Vorbis audio data."); // System.exit(0); // } // // // At this point, we're sure we're Vorbis. We've set up the logical // // (Ogg) bitstream decoder. Get the comment and codebook headers and // // set up the Vorbis decoder // // // The next two packets in order are the comment and codebook headers. // // They're likely large and may span multiple pages. Thus we reead // // and submit data until we get our two pacakets, watching that no // // pages are missing. If a page is missing, error out; losing a // // header page is the only place where missing data is fatal. */ // // int i = 0; // while (i < 2) { // while (i < 2) { // // int result = oy.pageout(og); // if (result == 0) // break; // Need more data // // Don't complain about missing or corrupt data yet. We'll // // catch it at the packet output phase // // if (result == 1) { // os.pagein(og); // we can ignore any errors here // // as they'll also become apparent // // at packetout // while (i < 2) { // result = os.packetout(op); // if (result == 0) // break; // if (result == -1) { // // Uh oh; data at some point was corrupted or missing! // // We can't tolerate that in a header. Die. // Log.error("Corrupt secondary header. Exiting."); // System.exit(0); // } // vi.synthesis_headerin(vc, op); // i++; // } // } // } // // no harm in not checking before adding more // index = oy.buffer(4096); // buffer = oy.data; // try { // bytes = input.read(buffer, index, 4096); // } catch (Exception e) { // Log.error("Failed to read Vorbis: "); // Log.error(e); // System.exit(0); // } // if (bytes == 0 && i < 2) { // Log.error("End of file before finding all Vorbis headers!"); // System.exit(0); // } // oy.wrote(bytes); // } // // convsize = 4096 / vi.channels; // // // OK, got and parsed all three headers. Initialize the Vorbis // // packet->PCM decoder. // vd.synthesis_init(vi); // central decode state // vb.init(vd); // local state for most of the decode // // so multiple block decodes can // // proceed in parallel. We could init // // multiple vorbis_block structures // // for vd here // // float[][][] _pcm = new float[1][][]; // int[] _index = new int[vi.channels]; // // The rest is just a straight decode loop until end of stream // while (eos == 0) { // while (eos == 0) { // // int result = oy.pageout(og); // if (result == 0) // break; // need more data // if (result == -1) { // missing or corrupt data at this page position // Log.error("Corrupt or missing data in bitstream; continuing..."); // } else { // os.pagein(og); // can safely ignore errors at // // this point // while (true) { // result = os.packetout(op); // // if (result == 0) // break; // need more data // if (result == -1) { // missing or corrupt data at this page position // // no reason to complain; already complained above // } else { // // we have a packet. Decode it // int samples; // if (vb.synthesis(op) == 0) { // test for success! // vd.synthesis_blockin(vb); // } // // // **pcm is a multichannel float vector. In stereo, for // // example, pcm[0] is left, and pcm[1] is right. samples is // // the size of each channel. Convert the float values // // (-1.<=range<=1.) to whatever PCM format and write it out // // while ((samples = vd.synthesis_pcmout(_pcm, // _index)) > 0) { // float[][] pcm = _pcm[0]; // //boolean clipflag = false; // int bout = (samples < convsize ? samples // : convsize); // // // convert floats to 16 bit signed ints (host order) and // // interleave // for (i = 0; i < vi.channels; i++) { // int ptr = i * 2; // //int ptr=i; // int mono = _index[i]; // for (int j = 0; j < bout; j++) { // int val = (int) (pcm[i][mono + j] * 32767.); // // short val=(short)(pcm[i][mono+j]*32767.); // // int val=(int)Math.round(pcm[i][mono+j]*32767.); // // might as well guard against clipping // if (val > 32767) { // val = 32767; // //clipflag = true; // } // if (val < -32768) { // val = -32768; // //clipflag = true; // } // if (val < 0) // val = val | 0x8000; // // if (bigEndian) { // convbuffer[ptr] = (byte) (val >>> 8); // convbuffer[ptr + 1] = (byte) (val); // } else { // convbuffer[ptr] = (byte) (val); // convbuffer[ptr + 1] = (byte) (val >>> 8); // } // ptr += 2 * (vi.channels); // } // } // // dataout.write(convbuffer, 0, 2 * vi.channels * bout); // // vd.synthesis_read(bout); // tell libvorbis how // // many samples we // // actually consumed // } // } // } // if (og.eos() != 0) // eos = 1; // } // } // if (eos == 0) { // index = oy.buffer(4096); // if (index >= 0) { // buffer = oy.data; // try { // bytes = input.read(buffer, index, 4096); // } catch (Exception e) { // Log.error("Failure during vorbis decoding"); // Log.error(e); // return null; // } // } else { // bytes = 0; // } // oy.wrote(bytes); // if (bytes == 0) // eos = 1; // } // } // // // clean up this logical bitstream; before exit we see if we're // // followed by another [chained] // // os.clear(); // // // ogg_page and ogg_packet structs always point to storage in // // libvorbis. They're never freed or manipulated directly // // vb.clear(); // vd.clear(); // vi.clear(); // must be called last // } // // // OK, clean up the framer // oy.clear(); // OggData ogg = new OggData(); // ogg.channels = vi.channels; // ogg.rate = vi.rate; OggInputStream oggInput = new OggInputStream(input); boolean done = false; while (!oggInput.atEnd()) { dataout.write(oggInput.read()); } OggData ogg = new OggData(); ogg.channels = oggInput.getChannels(); ogg.rate = oggInput.getRate(); byte[] data = dataout.toByteArray(); ogg.data = ByteBuffer.allocateDirect(data.length); ogg.data.put(data); ogg.data.rewind(); return ogg; }
[ "public", "OggData", "getData", "(", "InputStream", "input", ")", "throws", "IOException", "{", "if", "(", "input", "==", "null", ")", "{", "throw", "new", "IOException", "(", "\"Failed to read OGG, source does not exist?\"", ")", ";", "}", "ByteArrayOutputStream", "dataout", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "//\t\tSyncState oy = new SyncState(); // sync and verify incoming physical bitstream\r", "//\t\tStreamState os = new StreamState(); // take physical pages, weld into a logical stream of packets\r", "//\t\tPage og = new Page(); // one Ogg bitstream page. Vorbis packets are inside\r", "//\t\tPacket op = new Packet(); // one raw packet of data for decode\r", "//\r", "//\t\tInfo vi = new Info(); // struct that stores all the static vorbis bitstream settings\r", "//\t\tComment vc = new Comment(); // struct that stores all the bitstream user comments\r", "//\t\tDspState vd = new DspState(); // central working state for the packet->PCM decoder\r", "//\t\tBlock vb = new Block(vd); // local working space for packet->PCM decode\r", "//\r", "//\t\tbyte[] buffer;\r", "//\t\tint bytes = 0;\r", "//\r", "//\t\tboolean bigEndian = ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN);\r", "//\t\t// Decode setup\r", "//\r", "//\t\toy.init(); // Now we can read pages\r", "//\r", "//\t\twhile (true) { // we repeat if the bitstream is chained\r", "//\t\t\tint eos = 0;\r", "//\r", "//\t\t\t// grab some data at the head of the stream. We want the first page\r", "//\t\t\t// (which is guaranteed to be small and only contain the Vorbis\r", "//\t\t\t// stream initial header) We need the first page to get the stream\r", "//\t\t\t// serialno.\r", "//\r", "//\t\t\t// submit a 4k block to libvorbis' Ogg layer\r", "//\t\t\tint index = oy.buffer(4096);\r", "//\t\t\t\r", "//\t\t\tbuffer = oy.data;\r", "//\t\t\ttry {\r", "//\t\t\t\tbytes = input.read(buffer, index, 4096);\r", "//\t\t\t} catch (Exception e) {\r", "//\t\t\t\tLog.error(\"Failure reading in vorbis\");\r", "//\t\t\t\tLog.error(e);\r", "//\t\t\t\tSystem.exit(0);\r", "//\t\t\t}\r", "//\t\t\toy.wrote(bytes);\r", "//\r", "//\t\t\t// Get the first page.\r", "//\t\t\tif (oy.pageout(og) != 1) {\r", "//\t\t\t\t// have we simply run out of data? If so, we're done.\r", "//\t\t\t\tif (bytes < 4096)\r", "//\t\t\t\t\tbreak;\r", "//\r", "//\t\t\t\t// error case. Must not be Vorbis data\r", "//\t\t\t\tLog.error(\"Input does not appear to be an Ogg bitstream.\");\r", "//\t\t\t\tSystem.exit(0);\r", "//\t\t\t}\r", "//\r", "//\t\t\t// Get the serial number and set up the rest of decode.\r", "//\t\t\t// serialno first; use it to set up a logical stream\r", "//\t\t\tos.init(og.serialno());\r", "//\r", "//\t\t\t// extract the initial header from the first page and verify that the\r", "//\t\t\t// Ogg bitstream is in fact Vorbis data\r", "//\r", "//\t\t\t// I handle the initial header first instead of just having the code\r", "//\t\t\t// read all three Vorbis headers at once because reading the initial\r", "//\t\t\t// header is an easy way to identify a Vorbis bitstream and it's\r", "//\t\t\t// useful to see that functionality seperated out.\r", "//\r", "//\t\t\tvi.init();\r", "//\t\t\tvc.init();\r", "//\t\t\tif (os.pagein(og) < 0) {\r", "//\t\t\t\t// error; stream version mismatch perhaps\r", "//\t\t\t\tLog.error(\"Error reading first page of Ogg bitstream data.\");\r", "//\t\t\t\tSystem.exit(0);\r", "//\t\t\t}\r", "//\r", "//\t\t\tif (os.packetout(op) != 1) {\r", "//\t\t\t\t// no page? must not be vorbis\r", "//\t\t\t\tLog.error(\"Error reading initial header packet.\");\r", "//\t\t\t\tSystem.exit(0);\r", "//\t\t\t}\r", "//\r", "//\t\t\tif (vi.synthesis_headerin(vc, op) < 0) {\r", "//\t\t\t\t// error case; not a vorbis header\r", "//\t\t\t\tLog.error(\"This Ogg bitstream does not contain Vorbis audio data.\");\r", "//\t\t\t\tSystem.exit(0);\r", "//\t\t\t}\r", "//\r", "//\t\t\t// At this point, we're sure we're Vorbis. We've set up the logical\r", "//\t\t\t// (Ogg) bitstream decoder. Get the comment and codebook headers and\r", "//\t\t\t// set up the Vorbis decoder\r", "//\r", "//\t\t\t// The next two packets in order are the comment and codebook headers.\r", "//\t\t\t// They're likely large and may span multiple pages. Thus we reead\r", "//\t\t\t// and submit data until we get our two pacakets, watching that no\r", "//\t\t\t// pages are missing. If a page is missing, error out; losing a\r", "//\t\t\t// header page is the only place where missing data is fatal. */\r", "//\r", "//\t\t\tint i = 0;\r", "//\t\t\twhile (i < 2) {\r", "//\t\t\t\twhile (i < 2) {\r", "//\r", "//\t\t\t\t\tint result = oy.pageout(og);\r", "//\t\t\t\t\tif (result == 0)\r", "//\t\t\t\t\t\tbreak; // Need more data\r", "//\t\t\t\t\t// Don't complain about missing or corrupt data yet. We'll\r", "//\t\t\t\t\t// catch it at the packet output phase\r", "//\r", "//\t\t\t\t\tif (result == 1) {\r", "//\t\t\t\t\t\tos.pagein(og); // we can ignore any errors here\r", "//\t\t\t\t\t\t// as they'll also become apparent\r", "//\t\t\t\t\t\t// at packetout\r", "//\t\t\t\t\t\twhile (i < 2) {\r", "//\t\t\t\t\t\t\tresult = os.packetout(op);\r", "//\t\t\t\t\t\t\tif (result == 0)\r", "//\t\t\t\t\t\t\t\tbreak;\r", "//\t\t\t\t\t\t\tif (result == -1) {\r", "//\t\t\t\t\t\t\t\t// Uh oh; data at some point was corrupted or missing!\r", "//\t\t\t\t\t\t\t\t// We can't tolerate that in a header. Die.\r", "//\t\t\t\t\t\t\t\tLog.error(\"Corrupt secondary header. Exiting.\");\r", "//\t\t\t\t\t\t\t\tSystem.exit(0);\r", "//\t\t\t\t\t\t\t}\r", "//\t\t\t\t\t\t\tvi.synthesis_headerin(vc, op);\r", "//\t\t\t\t\t\t\ti++;\r", "//\t\t\t\t\t\t}\r", "//\t\t\t\t\t}\r", "//\t\t\t\t}\r", "//\t\t\t\t// no harm in not checking before adding more\r", "//\t\t\t\tindex = oy.buffer(4096);\r", "//\t\t\t\tbuffer = oy.data;\r", "//\t\t\t\ttry {\r", "//\t\t\t\t\tbytes = input.read(buffer, index, 4096);\r", "//\t\t\t\t} catch (Exception e) {\r", "//\t\t\t\t\tLog.error(\"Failed to read Vorbis: \");\r", "//\t\t\t\t\tLog.error(e);\r", "//\t\t\t\t\tSystem.exit(0);\r", "//\t\t\t\t}\r", "//\t\t\t\tif (bytes == 0 && i < 2) {\r", "//\t\t\t\t\tLog.error(\"End of file before finding all Vorbis headers!\");\r", "//\t\t\t\t\tSystem.exit(0);\r", "//\t\t\t\t}\r", "//\t\t\t\toy.wrote(bytes);\r", "//\t\t\t}\r", "//\r", "//\t\t\tconvsize = 4096 / vi.channels;\r", "//\r", "//\t\t\t// OK, got and parsed all three headers. Initialize the Vorbis\r", "//\t\t\t// packet->PCM decoder.\r", "//\t\t\tvd.synthesis_init(vi); // central decode state\r", "//\t\t\tvb.init(vd); // local state for most of the decode\r", "//\t\t\t// so multiple block decodes can\r", "//\t\t\t// proceed in parallel. We could init\r", "//\t\t\t// multiple vorbis_block structures\r", "//\t\t\t// for vd here\r", "//\r", "//\t\t\tfloat[][][] _pcm = new float[1][][];\r", "//\t\t\tint[] _index = new int[vi.channels];\r", "//\t\t\t// The rest is just a straight decode loop until end of stream\r", "//\t\t\twhile (eos == 0) {\r", "//\t\t\t\twhile (eos == 0) {\r", "//\r", "//\t\t\t\t\tint result = oy.pageout(og);\r", "//\t\t\t\t\tif (result == 0)\r", "//\t\t\t\t\t\tbreak; // need more data\r", "//\t\t\t\t\tif (result == -1) { // missing or corrupt data at this page position\r", "//\t\t\t\t\t\tLog.error(\"Corrupt or missing data in bitstream; continuing...\");\r", "//\t\t\t\t\t} else {\r", "//\t\t\t\t\t\tos.pagein(og); // can safely ignore errors at\r", "//\t\t\t\t\t\t// this point\r", "//\t\t\t\t\t\twhile (true) {\r", "//\t\t\t\t\t\t\tresult = os.packetout(op);\r", "//\r", "//\t\t\t\t\t\t\tif (result == 0)\r", "//\t\t\t\t\t\t\t\tbreak; // need more data\r", "//\t\t\t\t\t\t\tif (result == -1) { // missing or corrupt data at this page position\r", "//\t\t\t\t\t\t\t\t// no reason to complain; already complained above\r", "//\t\t\t\t\t\t\t} else {\r", "//\t\t\t\t\t\t\t\t// we have a packet. Decode it\r", "//\t\t\t\t\t\t\t\tint samples;\r", "//\t\t\t\t\t\t\t\tif (vb.synthesis(op) == 0) { // test for success!\r", "//\t\t\t\t\t\t\t\t\tvd.synthesis_blockin(vb);\r", "//\t\t\t\t\t\t\t\t}\r", "//\r", "//\t\t\t\t\t\t\t\t// **pcm is a multichannel float vector. In stereo, for\r", "//\t\t\t\t\t\t\t\t// example, pcm[0] is left, and pcm[1] is right. samples is\r", "//\t\t\t\t\t\t\t\t// the size of each channel. Convert the float values\r", "//\t\t\t\t\t\t\t\t// (-1.<=range<=1.) to whatever PCM format and write it out\r", "//\r", "//\t\t\t\t\t\t\t\twhile ((samples = vd.synthesis_pcmout(_pcm,\r", "//\t\t\t\t\t\t\t\t\t\t_index)) > 0) {\r", "//\t\t\t\t\t\t\t\t\tfloat[][] pcm = _pcm[0];\r", "//\t\t\t\t\t\t\t\t\t//boolean clipflag = false;\r", "//\t\t\t\t\t\t\t\t\tint bout = (samples < convsize ? samples\r", "//\t\t\t\t\t\t\t\t\t\t\t: convsize);\r", "//\r", "//\t\t\t\t\t\t\t\t\t// convert floats to 16 bit signed ints (host order) and\r", "//\t\t\t\t\t\t\t\t\t// interleave\r", "//\t\t\t\t\t\t\t\t\tfor (i = 0; i < vi.channels; i++) {\r", "//\t\t\t\t\t\t\t\t\t\tint ptr = i * 2;\r", "//\t\t\t\t\t\t\t\t\t\t//int ptr=i;\r", "//\t\t\t\t\t\t\t\t\t\tint mono = _index[i];\r", "//\t\t\t\t\t\t\t\t\t\tfor (int j = 0; j < bout; j++) {\r", "//\t\t\t\t\t\t\t\t\t\t\tint val = (int) (pcm[i][mono + j] * 32767.);\r", "//\t\t\t\t\t\t\t\t\t\t\t//\t\t\t short val=(short)(pcm[i][mono+j]*32767.);\r", "//\t\t\t\t\t\t\t\t\t\t\t//\t\t\t int val=(int)Math.round(pcm[i][mono+j]*32767.);\r", "//\t\t\t\t\t\t\t\t\t\t\t// might as well guard against clipping\r", "//\t\t\t\t\t\t\t\t\t\t\tif (val > 32767) {\r", "//\t\t\t\t\t\t\t\t\t\t\t\tval = 32767;\r", "//\t\t\t\t\t\t\t\t\t\t\t\t//clipflag = true;\r", "//\t\t\t\t\t\t\t\t\t\t\t}\r", "//\t\t\t\t\t\t\t\t\t\t\tif (val < -32768) {\r", "//\t\t\t\t\t\t\t\t\t\t\t\tval = -32768;\r", "//\t\t\t\t\t\t\t\t\t\t\t\t//clipflag = true;\r", "//\t\t\t\t\t\t\t\t\t\t\t}\r", "//\t\t\t\t\t\t\t\t\t\t\tif (val < 0)\r", "//\t\t\t\t\t\t\t\t\t\t\t\tval = val | 0x8000;\r", "//\t\t\t\t\r", "//\t\t\t\t\t\t\t\t\t\t\tif (bigEndian) {\r", "//\t\t\t\t\t\t\t\t\t\t\t\tconvbuffer[ptr] = (byte) (val >>> 8);\r", "//\t\t\t\t\t\t\t\t\t\t\t\tconvbuffer[ptr + 1] = (byte) (val);\r", "//\t\t\t\t\t\t\t\t\t\t\t} else {\r", "//\t\t\t\t\t\t\t\t\t\t\t\tconvbuffer[ptr] = (byte) (val);\r", "//\t\t\t\t\t\t\t\t\t\t\t\tconvbuffer[ptr + 1] = (byte) (val >>> 8);\r", "//\t\t\t\t\t\t\t\t\t\t\t}\r", "//\t\t\t\t\t\t\t\t\t\t\tptr += 2 * (vi.channels);\r", "//\t\t\t\t\t\t\t\t\t\t}\r", "//\t\t\t\t\t\t\t\t\t}\r", "//\r", "//\t\t\t\t\t\t\t\t\tdataout.write(convbuffer, 0, 2 * vi.channels * bout);\r", "//\r", "//\t\t\t\t\t\t\t\t\tvd.synthesis_read(bout); // tell libvorbis how\r", "//\t\t\t\t\t\t\t\t\t// many samples we\r", "//\t\t\t\t\t\t\t\t\t// actually consumed\r", "//\t\t\t\t\t\t\t\t}\r", "//\t\t\t\t\t\t\t}\r", "//\t\t\t\t\t\t}\r", "//\t\t\t\t\t\tif (og.eos() != 0)\r", "//\t\t\t\t\t\t\teos = 1;\r", "//\t\t\t\t\t}\r", "//\t\t\t\t}\r", "//\t\t\t\tif (eos == 0) {\r", "//\t\t\t\t\tindex = oy.buffer(4096);\r", "//\t\t\t\t\tif (index >= 0) {\r", "//\t\t\t\t\t\tbuffer = oy.data;\r", "//\t\t\t\t\t\ttry {\r", "//\t\t\t\t\t\t\tbytes = input.read(buffer, index, 4096);\r", "//\t\t\t\t\t\t} catch (Exception e) {\r", "//\t\t\t\t\t\t\tLog.error(\"Failure during vorbis decoding\");\r", "//\t\t\t\t\t\t\tLog.error(e);\r", "//\t\t\t\t\t\t\treturn null;\r", "//\t\t\t\t\t\t}\r", "//\t\t\t\t\t} else {\r", "//\t\t\t\t\t\tbytes = 0;\r", "//\t\t\t\t\t}\r", "//\t\t\t\t\toy.wrote(bytes);\r", "//\t\t\t\t\tif (bytes == 0)\r", "//\t\t\t\t\t\teos = 1;\r", "//\t\t\t\t}\r", "//\t\t\t}\r", "//\r", "//\t\t\t// clean up this logical bitstream; before exit we see if we're\r", "//\t\t\t// followed by another [chained]\r", "//\r", "//\t\t\tos.clear();\r", "//\r", "//\t\t\t// ogg_page and ogg_packet structs always point to storage in\r", "//\t\t\t// libvorbis. They're never freed or manipulated directly\r", "//\r", "//\t\t\tvb.clear();\r", "//\t\t\tvd.clear();\r", "//\t\t\tvi.clear(); // must be called last\r", "//\t\t}\r", "//\r", "//\t\t// OK, clean up the framer\r", "//\t\toy.clear();\r", "//\t\tOggData ogg = new OggData();\r", "//\t\togg.channels = vi.channels;\r", "//\t\togg.rate = vi.rate;\r", "OggInputStream", "oggInput", "=", "new", "OggInputStream", "(", "input", ")", ";", "boolean", "done", "=", "false", ";", "while", "(", "!", "oggInput", ".", "atEnd", "(", ")", ")", "{", "dataout", ".", "write", "(", "oggInput", ".", "read", "(", ")", ")", ";", "}", "OggData", "ogg", "=", "new", "OggData", "(", ")", ";", "ogg", ".", "channels", "=", "oggInput", ".", "getChannels", "(", ")", ";", "ogg", ".", "rate", "=", "oggInput", ".", "getRate", "(", ")", ";", "byte", "[", "]", "data", "=", "dataout", ".", "toByteArray", "(", ")", ";", "ogg", ".", "data", "=", "ByteBuffer", ".", "allocateDirect", "(", "data", ".", "length", ")", ";", "ogg", ".", "data", ".", "put", "(", "data", ")", ";", "ogg", ".", "data", ".", "rewind", "(", ")", ";", "return", "ogg", ";", "}" ]
Get the data out of an OGG file @param input The input stream from which to read the OGG file @return The data describing the OGG thats been read @throws IOException Indicaites a failure to read the OGG file
[ "Get", "the", "data", "out", "of", "an", "OGG", "file" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/openal/OggDecoder.java#L32-L328
1,729
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.createDirectory
private void createDirectory() { int numTables = 9; // Create the TrueType header writeByte((byte)0); writeByte((byte)1); writeByte((byte)0); writeByte((byte)0); realSize += 4; writeUShort(numTables); realSize += 2; // Create searchRange, entrySelector and rangeShift int maxPow = maxPow2(numTables); int searchRange = maxPow * 16; writeUShort(searchRange); realSize += 2; writeUShort(maxPow); realSize += 2; writeUShort((numTables * 16) - searchRange); realSize += 2; // Create space for the table entries writeString("cvt "); cvtDirOffset = currentPos; currentPos += 12; realSize += 16; if (hasFpgm()) { writeString("fpgm"); fpgmDirOffset = currentPos; currentPos += 12; realSize += 16; } writeString("glyf"); glyfDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("head"); headDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("hhea"); hheaDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("hmtx"); hmtxDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("loca"); locaDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("maxp"); maxpDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("prep"); prepDirOffset = currentPos; currentPos += 12; realSize += 16; }
java
private void createDirectory() { int numTables = 9; // Create the TrueType header writeByte((byte)0); writeByte((byte)1); writeByte((byte)0); writeByte((byte)0); realSize += 4; writeUShort(numTables); realSize += 2; // Create searchRange, entrySelector and rangeShift int maxPow = maxPow2(numTables); int searchRange = maxPow * 16; writeUShort(searchRange); realSize += 2; writeUShort(maxPow); realSize += 2; writeUShort((numTables * 16) - searchRange); realSize += 2; // Create space for the table entries writeString("cvt "); cvtDirOffset = currentPos; currentPos += 12; realSize += 16; if (hasFpgm()) { writeString("fpgm"); fpgmDirOffset = currentPos; currentPos += 12; realSize += 16; } writeString("glyf"); glyfDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("head"); headDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("hhea"); hheaDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("hmtx"); hmtxDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("loca"); locaDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("maxp"); maxpDirOffset = currentPos; currentPos += 12; realSize += 16; writeString("prep"); prepDirOffset = currentPos; currentPos += 12; realSize += 16; }
[ "private", "void", "createDirectory", "(", ")", "{", "int", "numTables", "=", "9", ";", "// Create the TrueType header", "writeByte", "(", "(", "byte", ")", "0", ")", ";", "writeByte", "(", "(", "byte", ")", "1", ")", ";", "writeByte", "(", "(", "byte", ")", "0", ")", ";", "writeByte", "(", "(", "byte", ")", "0", ")", ";", "realSize", "+=", "4", ";", "writeUShort", "(", "numTables", ")", ";", "realSize", "+=", "2", ";", "// Create searchRange, entrySelector and rangeShift", "int", "maxPow", "=", "maxPow2", "(", "numTables", ")", ";", "int", "searchRange", "=", "maxPow", "*", "16", ";", "writeUShort", "(", "searchRange", ")", ";", "realSize", "+=", "2", ";", "writeUShort", "(", "maxPow", ")", ";", "realSize", "+=", "2", ";", "writeUShort", "(", "(", "numTables", "*", "16", ")", "-", "searchRange", ")", ";", "realSize", "+=", "2", ";", "// Create space for the table entries", "writeString", "(", "\"cvt \"", ")", ";", "cvtDirOffset", "=", "currentPos", ";", "currentPos", "+=", "12", ";", "realSize", "+=", "16", ";", "if", "(", "hasFpgm", "(", ")", ")", "{", "writeString", "(", "\"fpgm\"", ")", ";", "fpgmDirOffset", "=", "currentPos", ";", "currentPos", "+=", "12", ";", "realSize", "+=", "16", ";", "}", "writeString", "(", "\"glyf\"", ")", ";", "glyfDirOffset", "=", "currentPos", ";", "currentPos", "+=", "12", ";", "realSize", "+=", "16", ";", "writeString", "(", "\"head\"", ")", ";", "headDirOffset", "=", "currentPos", ";", "currentPos", "+=", "12", ";", "realSize", "+=", "16", ";", "writeString", "(", "\"hhea\"", ")", ";", "hheaDirOffset", "=", "currentPos", ";", "currentPos", "+=", "12", ";", "realSize", "+=", "16", ";", "writeString", "(", "\"hmtx\"", ")", ";", "hmtxDirOffset", "=", "currentPos", ";", "currentPos", "+=", "12", ";", "realSize", "+=", "16", ";", "writeString", "(", "\"loca\"", ")", ";", "locaDirOffset", "=", "currentPos", ";", "currentPos", "+=", "12", ";", "realSize", "+=", "16", ";", "writeString", "(", "\"maxp\"", ")", ";", "maxpDirOffset", "=", "currentPos", ";", "currentPos", "+=", "12", ";", "realSize", "+=", "16", ";", "writeString", "(", "\"prep\"", ")", ";", "prepDirOffset", "=", "currentPos", ";", "currentPos", "+=", "12", ";", "realSize", "+=", "16", ";", "}" ]
Create the directory table
[ "Create", "the", "directory", "table" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L113-L184
1,730
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.createCvt
private void createCvt(FontFileReader in) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("cvt "); if (entry != null) { pad4(); seekTab(in, "cvt ", 0); System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()), 0, output, currentPos, (int)entry.getLength()); int checksum = getCheckSum(currentPos, (int)entry.getLength()); writeULong(cvtDirOffset, checksum); writeULong(cvtDirOffset + 4, currentPos); writeULong(cvtDirOffset + 8, (int)entry.getLength()); currentPos += (int)entry.getLength(); realSize += (int)entry.getLength(); } else { throw new IOException("Can't find cvt table"); } }
java
private void createCvt(FontFileReader in) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("cvt "); if (entry != null) { pad4(); seekTab(in, "cvt ", 0); System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()), 0, output, currentPos, (int)entry.getLength()); int checksum = getCheckSum(currentPos, (int)entry.getLength()); writeULong(cvtDirOffset, checksum); writeULong(cvtDirOffset + 4, currentPos); writeULong(cvtDirOffset + 8, (int)entry.getLength()); currentPos += (int)entry.getLength(); realSize += (int)entry.getLength(); } else { throw new IOException("Can't find cvt table"); } }
[ "private", "void", "createCvt", "(", "FontFileReader", "in", ")", "throws", "IOException", "{", "TTFDirTabEntry", "entry", "=", "(", "TTFDirTabEntry", ")", "dirTabs", ".", "get", "(", "\"cvt \"", ")", ";", "if", "(", "entry", "!=", "null", ")", "{", "pad4", "(", ")", ";", "seekTab", "(", "in", ",", "\"cvt \"", ",", "0", ")", ";", "System", ".", "arraycopy", "(", "in", ".", "getBytes", "(", "(", "int", ")", "entry", ".", "getOffset", "(", ")", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ",", "0", ",", "output", ",", "currentPos", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ";", "int", "checksum", "=", "getCheckSum", "(", "currentPos", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ";", "writeULong", "(", "cvtDirOffset", ",", "checksum", ")", ";", "writeULong", "(", "cvtDirOffset", "+", "4", ",", "currentPos", ")", ";", "writeULong", "(", "cvtDirOffset", "+", "8", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ";", "currentPos", "+=", "(", "int", ")", "entry", ".", "getLength", "(", ")", ";", "realSize", "+=", "(", "int", ")", "entry", ".", "getLength", "(", ")", ";", "}", "else", "{", "throw", "new", "IOException", "(", "\"Can't find cvt table\"", ")", ";", "}", "}" ]
Copy the cvt table as is from original font to subset font @param in The input to read the CVT from @throws IOException Indicates a failure to read the entry
[ "Copy", "the", "cvt", "table", "as", "is", "from", "original", "font", "to", "subset", "font" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L193-L210
1,731
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.createLoca
private void createLoca(int size) throws IOException { pad4(); locaOffset = currentPos; writeULong(locaDirOffset + 4, currentPos); writeULong(locaDirOffset + 8, size * 4 + 4); currentPos += size * 4 + 4; realSize += size * 4 + 4; }
java
private void createLoca(int size) throws IOException { pad4(); locaOffset = currentPos; writeULong(locaDirOffset + 4, currentPos); writeULong(locaDirOffset + 8, size * 4 + 4); currentPos += size * 4 + 4; realSize += size * 4 + 4; }
[ "private", "void", "createLoca", "(", "int", "size", ")", "throws", "IOException", "{", "pad4", "(", ")", ";", "locaOffset", "=", "currentPos", ";", "writeULong", "(", "locaDirOffset", "+", "4", ",", "currentPos", ")", ";", "writeULong", "(", "locaDirOffset", "+", "8", ",", "size", "*", "4", "+", "4", ")", ";", "currentPos", "+=", "size", "*", "4", "+", "4", ";", "realSize", "+=", "size", "*", "4", "+", "4", ";", "}" ]
Create an empty loca table without updating checksum @param size The size of the loca to create @throws IOException Indicate a failure to store the loca
[ "Create", "an", "empty", "loca", "table", "without", "updating", "checksum" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L255-L262
1,732
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.createMaxp
private void createMaxp(FontFileReader in, int size) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("maxp"); if (entry != null) { pad4(); seekTab(in, "maxp", 0); System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()), 0, output, currentPos, (int)entry.getLength()); writeUShort(currentPos + 4, size); int checksum = getCheckSum(currentPos, (int)entry.getLength()); writeULong(maxpDirOffset, checksum); writeULong(maxpDirOffset + 4, currentPos); writeULong(maxpDirOffset + 8, (int)entry.getLength()); currentPos += (int)entry.getLength(); realSize += (int)entry.getLength(); } else { throw new IOException("Can't find maxp table"); } }
java
private void createMaxp(FontFileReader in, int size) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("maxp"); if (entry != null) { pad4(); seekTab(in, "maxp", 0); System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()), 0, output, currentPos, (int)entry.getLength()); writeUShort(currentPos + 4, size); int checksum = getCheckSum(currentPos, (int)entry.getLength()); writeULong(maxpDirOffset, checksum); writeULong(maxpDirOffset + 4, currentPos); writeULong(maxpDirOffset + 8, (int)entry.getLength()); currentPos += (int)entry.getLength(); realSize += (int)entry.getLength(); } else { throw new IOException("Can't find maxp table"); } }
[ "private", "void", "createMaxp", "(", "FontFileReader", "in", ",", "int", "size", ")", "throws", "IOException", "{", "TTFDirTabEntry", "entry", "=", "(", "TTFDirTabEntry", ")", "dirTabs", ".", "get", "(", "\"maxp\"", ")", ";", "if", "(", "entry", "!=", "null", ")", "{", "pad4", "(", ")", ";", "seekTab", "(", "in", ",", "\"maxp\"", ",", "0", ")", ";", "System", ".", "arraycopy", "(", "in", ".", "getBytes", "(", "(", "int", ")", "entry", ".", "getOffset", "(", ")", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ",", "0", ",", "output", ",", "currentPos", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ";", "writeUShort", "(", "currentPos", "+", "4", ",", "size", ")", ";", "int", "checksum", "=", "getCheckSum", "(", "currentPos", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ";", "writeULong", "(", "maxpDirOffset", ",", "checksum", ")", ";", "writeULong", "(", "maxpDirOffset", "+", "4", ",", "currentPos", ")", ";", "writeULong", "(", "maxpDirOffset", "+", "8", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ";", "currentPos", "+=", "(", "int", ")", "entry", ".", "getLength", "(", ")", ";", "realSize", "+=", "(", "int", ")", "entry", ".", "getLength", "(", ")", ";", "}", "else", "{", "throw", "new", "IOException", "(", "\"Can't find maxp table\"", ")", ";", "}", "}" ]
Copy the maxp table as is from original font to subset font and set num glyphs to size @param in The reader from which to obtain the info @param size The size of the MAXP table to write @throws IOException Indicates a failure to write
[ "Copy", "the", "maxp", "table", "as", "is", "from", "original", "font", "to", "subset", "font", "and", "set", "num", "glyphs", "to", "size" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L273-L291
1,733
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.createHead
private void createHead(FontFileReader in) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("head"); if (entry != null) { pad4(); seekTab(in, "head", 0); System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()), 0, output, currentPos, (int)entry.getLength()); checkSumAdjustmentOffset = currentPos + 8; output[currentPos + 8] = 0; // Set checkSumAdjustment to 0 output[currentPos + 9] = 0; output[currentPos + 10] = 0; output[currentPos + 11] = 0; output[currentPos + 50] = 0; // long locaformat output[currentPos + 51] = 1; // long locaformat int checksum = getCheckSum(currentPos, (int)entry.getLength()); writeULong(headDirOffset, checksum); writeULong(headDirOffset + 4, currentPos); writeULong(headDirOffset + 8, (int)entry.getLength()); currentPos += (int)entry.getLength(); realSize += (int)entry.getLength(); } else { throw new IOException("Can't find head table"); } }
java
private void createHead(FontFileReader in) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("head"); if (entry != null) { pad4(); seekTab(in, "head", 0); System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()), 0, output, currentPos, (int)entry.getLength()); checkSumAdjustmentOffset = currentPos + 8; output[currentPos + 8] = 0; // Set checkSumAdjustment to 0 output[currentPos + 9] = 0; output[currentPos + 10] = 0; output[currentPos + 11] = 0; output[currentPos + 50] = 0; // long locaformat output[currentPos + 51] = 1; // long locaformat int checksum = getCheckSum(currentPos, (int)entry.getLength()); writeULong(headDirOffset, checksum); writeULong(headDirOffset + 4, currentPos); writeULong(headDirOffset + 8, (int)entry.getLength()); currentPos += (int)entry.getLength(); realSize += (int)entry.getLength(); } else { throw new IOException("Can't find head table"); } }
[ "private", "void", "createHead", "(", "FontFileReader", "in", ")", "throws", "IOException", "{", "TTFDirTabEntry", "entry", "=", "(", "TTFDirTabEntry", ")", "dirTabs", ".", "get", "(", "\"head\"", ")", ";", "if", "(", "entry", "!=", "null", ")", "{", "pad4", "(", ")", ";", "seekTab", "(", "in", ",", "\"head\"", ",", "0", ")", ";", "System", ".", "arraycopy", "(", "in", ".", "getBytes", "(", "(", "int", ")", "entry", ".", "getOffset", "(", ")", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ",", "0", ",", "output", ",", "currentPos", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ";", "checkSumAdjustmentOffset", "=", "currentPos", "+", "8", ";", "output", "[", "currentPos", "+", "8", "]", "=", "0", ";", "// Set checkSumAdjustment to 0", "output", "[", "currentPos", "+", "9", "]", "=", "0", ";", "output", "[", "currentPos", "+", "10", "]", "=", "0", ";", "output", "[", "currentPos", "+", "11", "]", "=", "0", ";", "output", "[", "currentPos", "+", "50", "]", "=", "0", ";", "// long locaformat", "output", "[", "currentPos", "+", "51", "]", "=", "1", ";", "// long locaformat", "int", "checksum", "=", "getCheckSum", "(", "currentPos", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ";", "writeULong", "(", "headDirOffset", ",", "checksum", ")", ";", "writeULong", "(", "headDirOffset", "+", "4", ",", "currentPos", ")", ";", "writeULong", "(", "headDirOffset", "+", "8", ",", "(", "int", ")", "entry", ".", "getLength", "(", ")", ")", ";", "currentPos", "+=", "(", "int", ")", "entry", ".", "getLength", "(", ")", ";", "realSize", "+=", "(", "int", ")", "entry", ".", "getLength", "(", ")", ";", "}", "else", "{", "throw", "new", "IOException", "(", "\"Can't find head table\"", ")", ";", "}", "}" ]
Copy the head table as is from original font to subset font and set indexToLocaFormat to long and set checkSumAdjustment to 0, store offset to checkSumAdjustment in checkSumAdjustmentOffset @param in The reader to read the HEAD table from @throws IOException Failure to read the table
[ "Copy", "the", "head", "table", "as", "is", "from", "original", "font", "to", "subset", "font", "and", "set", "indexToLocaFormat", "to", "long", "and", "set", "checkSumAdjustment", "to", "0", "store", "offset", "to", "checkSumAdjustment", "in", "checkSumAdjustmentOffset" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L358-L384
1,734
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.createGlyf
private void createGlyf(FontFileReader in, Map glyphs) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("glyf"); int size = 0; int start = 0; int endOffset = 0; // Store this as the last loca if (entry != null) { pad4(); start = currentPos; /* Loca table must be in order by glyph index, so build * an array first and then write the glyph info and * location offset. */ int[] origIndexes = new int[glyphs.size()]; Iterator e = glyphs.keySet().iterator(); while (e.hasNext()) { Integer origIndex = (Integer)e.next(); Integer subsetIndex = (Integer)glyphs.get(origIndex); origIndexes[subsetIndex.intValue()] = origIndex.intValue(); } for (int i = 0; i < origIndexes.length; i++) { int glyphLength = 0; int nextOffset = 0; int origGlyphIndex = origIndexes[i]; if (origGlyphIndex >= (mtxTab.length - 1)) { nextOffset = (int)lastLoca; } else { nextOffset = (int)mtxTab[origGlyphIndex + 1].getOffset(); } glyphLength = nextOffset - (int)mtxTab[origGlyphIndex].getOffset(); // Copy glyph System.arraycopy( in.getBytes((int)entry.getOffset() + (int)mtxTab[origGlyphIndex].getOffset(), glyphLength), 0, output, currentPos, glyphLength); // Update loca table writeULong(locaOffset + i * 4, currentPos - start); if ((currentPos - start + glyphLength) > endOffset) { endOffset = (currentPos - start + glyphLength); } currentPos += glyphLength; realSize += glyphLength; } size = currentPos - start; int checksum = getCheckSum(start, size); writeULong(glyfDirOffset, checksum); writeULong(glyfDirOffset + 4, start); writeULong(glyfDirOffset + 8, size); currentPos += 12; realSize += 12; // Update loca checksum and last loca index writeULong(locaOffset + glyphs.size() * 4, endOffset); checksum = getCheckSum(locaOffset, glyphs.size() * 4 + 4); writeULong(locaDirOffset, checksum); } else { throw new IOException("Can't find glyf table"); } }
java
private void createGlyf(FontFileReader in, Map glyphs) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("glyf"); int size = 0; int start = 0; int endOffset = 0; // Store this as the last loca if (entry != null) { pad4(); start = currentPos; /* Loca table must be in order by glyph index, so build * an array first and then write the glyph info and * location offset. */ int[] origIndexes = new int[glyphs.size()]; Iterator e = glyphs.keySet().iterator(); while (e.hasNext()) { Integer origIndex = (Integer)e.next(); Integer subsetIndex = (Integer)glyphs.get(origIndex); origIndexes[subsetIndex.intValue()] = origIndex.intValue(); } for (int i = 0; i < origIndexes.length; i++) { int glyphLength = 0; int nextOffset = 0; int origGlyphIndex = origIndexes[i]; if (origGlyphIndex >= (mtxTab.length - 1)) { nextOffset = (int)lastLoca; } else { nextOffset = (int)mtxTab[origGlyphIndex + 1].getOffset(); } glyphLength = nextOffset - (int)mtxTab[origGlyphIndex].getOffset(); // Copy glyph System.arraycopy( in.getBytes((int)entry.getOffset() + (int)mtxTab[origGlyphIndex].getOffset(), glyphLength), 0, output, currentPos, glyphLength); // Update loca table writeULong(locaOffset + i * 4, currentPos - start); if ((currentPos - start + glyphLength) > endOffset) { endOffset = (currentPos - start + glyphLength); } currentPos += glyphLength; realSize += glyphLength; } size = currentPos - start; int checksum = getCheckSum(start, size); writeULong(glyfDirOffset, checksum); writeULong(glyfDirOffset + 4, start); writeULong(glyfDirOffset + 8, size); currentPos += 12; realSize += 12; // Update loca checksum and last loca index writeULong(locaOffset + glyphs.size() * 4, endOffset); checksum = getCheckSum(locaOffset, glyphs.size() * 4 + 4); writeULong(locaDirOffset, checksum); } else { throw new IOException("Can't find glyf table"); } }
[ "private", "void", "createGlyf", "(", "FontFileReader", "in", ",", "Map", "glyphs", ")", "throws", "IOException", "{", "TTFDirTabEntry", "entry", "=", "(", "TTFDirTabEntry", ")", "dirTabs", ".", "get", "(", "\"glyf\"", ")", ";", "int", "size", "=", "0", ";", "int", "start", "=", "0", ";", "int", "endOffset", "=", "0", ";", "// Store this as the last loca", "if", "(", "entry", "!=", "null", ")", "{", "pad4", "(", ")", ";", "start", "=", "currentPos", ";", "/* Loca table must be in order by glyph index, so build\n * an array first and then write the glyph info and\n * location offset.\n */", "int", "[", "]", "origIndexes", "=", "new", "int", "[", "glyphs", ".", "size", "(", ")", "]", ";", "Iterator", "e", "=", "glyphs", ".", "keySet", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "e", ".", "hasNext", "(", ")", ")", "{", "Integer", "origIndex", "=", "(", "Integer", ")", "e", ".", "next", "(", ")", ";", "Integer", "subsetIndex", "=", "(", "Integer", ")", "glyphs", ".", "get", "(", "origIndex", ")", ";", "origIndexes", "[", "subsetIndex", ".", "intValue", "(", ")", "]", "=", "origIndex", ".", "intValue", "(", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "origIndexes", ".", "length", ";", "i", "++", ")", "{", "int", "glyphLength", "=", "0", ";", "int", "nextOffset", "=", "0", ";", "int", "origGlyphIndex", "=", "origIndexes", "[", "i", "]", ";", "if", "(", "origGlyphIndex", ">=", "(", "mtxTab", ".", "length", "-", "1", ")", ")", "{", "nextOffset", "=", "(", "int", ")", "lastLoca", ";", "}", "else", "{", "nextOffset", "=", "(", "int", ")", "mtxTab", "[", "origGlyphIndex", "+", "1", "]", ".", "getOffset", "(", ")", ";", "}", "glyphLength", "=", "nextOffset", "-", "(", "int", ")", "mtxTab", "[", "origGlyphIndex", "]", ".", "getOffset", "(", ")", ";", "// Copy glyph", "System", ".", "arraycopy", "(", "in", ".", "getBytes", "(", "(", "int", ")", "entry", ".", "getOffset", "(", ")", "+", "(", "int", ")", "mtxTab", "[", "origGlyphIndex", "]", ".", "getOffset", "(", ")", ",", "glyphLength", ")", ",", "0", ",", "output", ",", "currentPos", ",", "glyphLength", ")", ";", "// Update loca table", "writeULong", "(", "locaOffset", "+", "i", "*", "4", ",", "currentPos", "-", "start", ")", ";", "if", "(", "(", "currentPos", "-", "start", "+", "glyphLength", ")", ">", "endOffset", ")", "{", "endOffset", "=", "(", "currentPos", "-", "start", "+", "glyphLength", ")", ";", "}", "currentPos", "+=", "glyphLength", ";", "realSize", "+=", "glyphLength", ";", "}", "size", "=", "currentPos", "-", "start", ";", "int", "checksum", "=", "getCheckSum", "(", "start", ",", "size", ")", ";", "writeULong", "(", "glyfDirOffset", ",", "checksum", ")", ";", "writeULong", "(", "glyfDirOffset", "+", "4", ",", "start", ")", ";", "writeULong", "(", "glyfDirOffset", "+", "8", ",", "size", ")", ";", "currentPos", "+=", "12", ";", "realSize", "+=", "12", ";", "// Update loca checksum and last loca index", "writeULong", "(", "locaOffset", "+", "glyphs", ".", "size", "(", ")", "*", "4", ",", "endOffset", ")", ";", "checksum", "=", "getCheckSum", "(", "locaOffset", ",", "glyphs", ".", "size", "(", ")", "*", "4", "+", "4", ")", ";", "writeULong", "(", "locaDirOffset", ",", "checksum", ")", ";", "}", "else", "{", "throw", "new", "IOException", "(", "\"Can't find glyf table\"", ")", ";", "}", "}" ]
Create the glyf table and fill in loca table @param in Reader to get the table from @param glyphs The glpyhs table to populate @throws IOException Indicates a failure to read data
[ "Create", "the", "glyf", "table", "and", "fill", "in", "loca", "table" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L394-L464
1,735
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.getIncludedGlyphs
private List getIncludedGlyphs(FontFileReader in, int glyphOffset, Integer glyphIdx) throws IOException { List ret = new ArrayList(); ret.add(glyphIdx); int offset = glyphOffset + (int)mtxTab[glyphIdx.intValue()].getOffset() + 10; Integer compositeIdx = null; int flags = 0; boolean moreComposites = true; while (moreComposites) { flags = in.readTTFUShort(offset); compositeIdx = new Integer(in.readTTFUShort(offset + 2)); ret.add(compositeIdx); offset += 4; if ((flags & 1) > 0) { // ARG_1_AND_ARG_2_ARE_WORDS offset += 4; } else { offset += 2; } if ((flags & 8) > 0) { offset += 2; // WE_HAVE_A_SCALE } else if ((flags & 64) > 0) { offset += 4; // WE_HAVE_AN_X_AND_Y_SCALE } else if ((flags & 128) > 0) { offset += 8; // WE_HAVE_A_TWO_BY_TWO } if ((flags & 32) > 0) { moreComposites = true; } else { moreComposites = false; } } return ret; }
java
private List getIncludedGlyphs(FontFileReader in, int glyphOffset, Integer glyphIdx) throws IOException { List ret = new ArrayList(); ret.add(glyphIdx); int offset = glyphOffset + (int)mtxTab[glyphIdx.intValue()].getOffset() + 10; Integer compositeIdx = null; int flags = 0; boolean moreComposites = true; while (moreComposites) { flags = in.readTTFUShort(offset); compositeIdx = new Integer(in.readTTFUShort(offset + 2)); ret.add(compositeIdx); offset += 4; if ((flags & 1) > 0) { // ARG_1_AND_ARG_2_ARE_WORDS offset += 4; } else { offset += 2; } if ((flags & 8) > 0) { offset += 2; // WE_HAVE_A_SCALE } else if ((flags & 64) > 0) { offset += 4; // WE_HAVE_AN_X_AND_Y_SCALE } else if ((flags & 128) > 0) { offset += 8; // WE_HAVE_A_TWO_BY_TWO } if ((flags & 32) > 0) { moreComposites = true; } else { moreComposites = false; } } return ret; }
[ "private", "List", "getIncludedGlyphs", "(", "FontFileReader", "in", ",", "int", "glyphOffset", ",", "Integer", "glyphIdx", ")", "throws", "IOException", "{", "List", "ret", "=", "new", "ArrayList", "(", ")", ";", "ret", ".", "add", "(", "glyphIdx", ")", ";", "int", "offset", "=", "glyphOffset", "+", "(", "int", ")", "mtxTab", "[", "glyphIdx", ".", "intValue", "(", ")", "]", ".", "getOffset", "(", ")", "+", "10", ";", "Integer", "compositeIdx", "=", "null", ";", "int", "flags", "=", "0", ";", "boolean", "moreComposites", "=", "true", ";", "while", "(", "moreComposites", ")", "{", "flags", "=", "in", ".", "readTTFUShort", "(", "offset", ")", ";", "compositeIdx", "=", "new", "Integer", "(", "in", ".", "readTTFUShort", "(", "offset", "+", "2", ")", ")", ";", "ret", ".", "add", "(", "compositeIdx", ")", ";", "offset", "+=", "4", ";", "if", "(", "(", "flags", "&", "1", ")", ">", "0", ")", "{", "// ARG_1_AND_ARG_2_ARE_WORDS", "offset", "+=", "4", ";", "}", "else", "{", "offset", "+=", "2", ";", "}", "if", "(", "(", "flags", "&", "8", ")", ">", "0", ")", "{", "offset", "+=", "2", ";", "// WE_HAVE_A_SCALE", "}", "else", "if", "(", "(", "flags", "&", "64", ")", ">", "0", ")", "{", "offset", "+=", "4", ";", "// WE_HAVE_AN_X_AND_Y_SCALE", "}", "else", "if", "(", "(", "flags", "&", "128", ")", ">", "0", ")", "{", "offset", "+=", "8", ";", "// WE_HAVE_A_TWO_BY_TWO", "}", "if", "(", "(", "flags", "&", "32", ")", ">", "0", ")", "{", "moreComposites", "=", "true", ";", "}", "else", "{", "moreComposites", "=", "false", ";", "}", "}", "return", "ret", ";", "}" ]
Returns a List containing the glyph itself plus all glyphs that this composite glyph uses @param in The input from which to determine the included glyphs @param glyphOffset The offset the glyph @param glyphIdx The index of the base glyph @return The list of glyphs building the composite @throws IOException Indicates a failure to read from the font file
[ "Returns", "a", "List", "containing", "the", "glyph", "itself", "plus", "all", "glyphs", "that", "this", "composite", "glyph", "uses" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L520-L557
1,736
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.remapComposite
private void remapComposite(FontFileReader in, Map glyphs, int glyphOffset, Integer glyphIdx) throws IOException { int offset = glyphOffset + (int)mtxTab[glyphIdx.intValue()].getOffset() + 10; Integer compositeIdx = null; int flags = 0; boolean moreComposites = true; while (moreComposites) { flags = in.readTTFUShort(offset); compositeIdx = new Integer(in.readTTFUShort(offset + 2)); Integer newIdx = (Integer)glyphs.get(compositeIdx); if (newIdx == null) { // This errormessage would look much better // if the fontname was printed to //log.error("An embedded font " // + "contains bad glyph data. " // + "Characters might not display " // + "correctly."); moreComposites = false; continue; } in.writeTTFUShort(offset + 2, newIdx.intValue()); offset += 4; if ((flags & 1) > 0) { // ARG_1_AND_ARG_2_ARE_WORDS offset += 4; } else { offset += 2; } if ((flags & 8) > 0) { offset += 2; // WE_HAVE_A_SCALE } else if ((flags & 64) > 0) { offset += 4; // WE_HAVE_AN_X_AND_Y_SCALE } else if ((flags & 128) > 0) { offset += 8; // WE_HAVE_A_TWO_BY_TWO } if ((flags & 32) > 0) { moreComposites = true; } else { moreComposites = false; } } }
java
private void remapComposite(FontFileReader in, Map glyphs, int glyphOffset, Integer glyphIdx) throws IOException { int offset = glyphOffset + (int)mtxTab[glyphIdx.intValue()].getOffset() + 10; Integer compositeIdx = null; int flags = 0; boolean moreComposites = true; while (moreComposites) { flags = in.readTTFUShort(offset); compositeIdx = new Integer(in.readTTFUShort(offset + 2)); Integer newIdx = (Integer)glyphs.get(compositeIdx); if (newIdx == null) { // This errormessage would look much better // if the fontname was printed to //log.error("An embedded font " // + "contains bad glyph data. " // + "Characters might not display " // + "correctly."); moreComposites = false; continue; } in.writeTTFUShort(offset + 2, newIdx.intValue()); offset += 4; if ((flags & 1) > 0) { // ARG_1_AND_ARG_2_ARE_WORDS offset += 4; } else { offset += 2; } if ((flags & 8) > 0) { offset += 2; // WE_HAVE_A_SCALE } else if ((flags & 64) > 0) { offset += 4; // WE_HAVE_AN_X_AND_Y_SCALE } else if ((flags & 128) > 0) { offset += 8; // WE_HAVE_A_TWO_BY_TWO } if ((flags & 32) > 0) { moreComposites = true; } else { moreComposites = false; } } }
[ "private", "void", "remapComposite", "(", "FontFileReader", "in", ",", "Map", "glyphs", ",", "int", "glyphOffset", ",", "Integer", "glyphIdx", ")", "throws", "IOException", "{", "int", "offset", "=", "glyphOffset", "+", "(", "int", ")", "mtxTab", "[", "glyphIdx", ".", "intValue", "(", ")", "]", ".", "getOffset", "(", ")", "+", "10", ";", "Integer", "compositeIdx", "=", "null", ";", "int", "flags", "=", "0", ";", "boolean", "moreComposites", "=", "true", ";", "while", "(", "moreComposites", ")", "{", "flags", "=", "in", ".", "readTTFUShort", "(", "offset", ")", ";", "compositeIdx", "=", "new", "Integer", "(", "in", ".", "readTTFUShort", "(", "offset", "+", "2", ")", ")", ";", "Integer", "newIdx", "=", "(", "Integer", ")", "glyphs", ".", "get", "(", "compositeIdx", ")", ";", "if", "(", "newIdx", "==", "null", ")", "{", "// This errormessage would look much better", "// if the fontname was printed to", "//log.error(\"An embedded font \"", "// + \"contains bad glyph data. \"", "// + \"Characters might not display \"", "// + \"correctly.\");", "moreComposites", "=", "false", ";", "continue", ";", "}", "in", ".", "writeTTFUShort", "(", "offset", "+", "2", ",", "newIdx", ".", "intValue", "(", ")", ")", ";", "offset", "+=", "4", ";", "if", "(", "(", "flags", "&", "1", ")", ">", "0", ")", "{", "// ARG_1_AND_ARG_2_ARE_WORDS", "offset", "+=", "4", ";", "}", "else", "{", "offset", "+=", "2", ";", "}", "if", "(", "(", "flags", "&", "8", ")", ">", "0", ")", "{", "offset", "+=", "2", ";", "// WE_HAVE_A_SCALE", "}", "else", "if", "(", "(", "flags", "&", "64", ")", ">", "0", ")", "{", "offset", "+=", "4", ";", "// WE_HAVE_AN_X_AND_Y_SCALE", "}", "else", "if", "(", "(", "flags", "&", "128", ")", ">", "0", ")", "{", "offset", "+=", "8", ";", "// WE_HAVE_A_TWO_BY_TWO", "}", "if", "(", "(", "flags", "&", "32", ")", ">", "0", ")", "{", "moreComposites", "=", "true", ";", "}", "else", "{", "moreComposites", "=", "false", ";", "}", "}", "}" ]
Rewrite all compositepointers in glyphindex glyphIdx @param in The input from which to remap @param glyphs The glyphs to remap @param glyphOffset The offset to start at @param glyphIdx The index of the glyph @throws IOException Indicates a failure to read from the font file.
[ "Rewrite", "all", "compositepointers", "in", "glyphindex", "glyphIdx" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L569-L619
1,737
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.scanGlyphs
private void scanGlyphs(FontFileReader in, Map glyphs) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("glyf"); Map newComposites = null; Map allComposites = new java.util.HashMap(); int newIndex = glyphs.size(); if (entry != null) { while (newComposites == null || newComposites.size() > 0) { // Inefficient to iterate through all glyphs newComposites = new java.util.HashMap(); Iterator e = glyphs.keySet().iterator(); while (e.hasNext()) { Integer origIndex = (Integer)e.next(); if (in.readTTFShort(entry.getOffset() + mtxTab[origIndex.intValue()].getOffset()) < 0) { // origIndex is a composite glyph allComposites.put(origIndex, glyphs.get(origIndex)); List composites = getIncludedGlyphs(in, (int)entry.getOffset(), origIndex); // Iterate through all composites pointed to // by this composite and check if they exists // in the glyphs map, add them if not. Iterator cps = composites.iterator(); while (cps.hasNext()) { Integer cIdx = (Integer)cps.next(); if (glyphs.get(cIdx) == null && newComposites.get(cIdx) == null) { newComposites.put(cIdx, new Integer(newIndex)); newIndex++; } } } } // Add composites to glyphs Iterator m = newComposites.keySet().iterator(); while (m.hasNext()) { Integer im = (Integer)m.next(); glyphs.put(im, newComposites.get(im)); } } // Iterate through all composites to remap their composite index Iterator ce = allComposites.keySet().iterator(); while (ce.hasNext()) { remapComposite(in, glyphs, (int)entry.getOffset(), (Integer)ce.next()); } } else { throw new IOException("Can't find glyf table"); } }
java
private void scanGlyphs(FontFileReader in, Map glyphs) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("glyf"); Map newComposites = null; Map allComposites = new java.util.HashMap(); int newIndex = glyphs.size(); if (entry != null) { while (newComposites == null || newComposites.size() > 0) { // Inefficient to iterate through all glyphs newComposites = new java.util.HashMap(); Iterator e = glyphs.keySet().iterator(); while (e.hasNext()) { Integer origIndex = (Integer)e.next(); if (in.readTTFShort(entry.getOffset() + mtxTab[origIndex.intValue()].getOffset()) < 0) { // origIndex is a composite glyph allComposites.put(origIndex, glyphs.get(origIndex)); List composites = getIncludedGlyphs(in, (int)entry.getOffset(), origIndex); // Iterate through all composites pointed to // by this composite and check if they exists // in the glyphs map, add them if not. Iterator cps = composites.iterator(); while (cps.hasNext()) { Integer cIdx = (Integer)cps.next(); if (glyphs.get(cIdx) == null && newComposites.get(cIdx) == null) { newComposites.put(cIdx, new Integer(newIndex)); newIndex++; } } } } // Add composites to glyphs Iterator m = newComposites.keySet().iterator(); while (m.hasNext()) { Integer im = (Integer)m.next(); glyphs.put(im, newComposites.get(im)); } } // Iterate through all composites to remap their composite index Iterator ce = allComposites.keySet().iterator(); while (ce.hasNext()) { remapComposite(in, glyphs, (int)entry.getOffset(), (Integer)ce.next()); } } else { throw new IOException("Can't find glyf table"); } }
[ "private", "void", "scanGlyphs", "(", "FontFileReader", "in", ",", "Map", "glyphs", ")", "throws", "IOException", "{", "TTFDirTabEntry", "entry", "=", "(", "TTFDirTabEntry", ")", "dirTabs", ".", "get", "(", "\"glyf\"", ")", ";", "Map", "newComposites", "=", "null", ";", "Map", "allComposites", "=", "new", "java", ".", "util", ".", "HashMap", "(", ")", ";", "int", "newIndex", "=", "glyphs", ".", "size", "(", ")", ";", "if", "(", "entry", "!=", "null", ")", "{", "while", "(", "newComposites", "==", "null", "||", "newComposites", ".", "size", "(", ")", ">", "0", ")", "{", "// Inefficient to iterate through all glyphs", "newComposites", "=", "new", "java", ".", "util", ".", "HashMap", "(", ")", ";", "Iterator", "e", "=", "glyphs", ".", "keySet", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "e", ".", "hasNext", "(", ")", ")", "{", "Integer", "origIndex", "=", "(", "Integer", ")", "e", ".", "next", "(", ")", ";", "if", "(", "in", ".", "readTTFShort", "(", "entry", ".", "getOffset", "(", ")", "+", "mtxTab", "[", "origIndex", ".", "intValue", "(", ")", "]", ".", "getOffset", "(", ")", ")", "<", "0", ")", "{", "// origIndex is a composite glyph", "allComposites", ".", "put", "(", "origIndex", ",", "glyphs", ".", "get", "(", "origIndex", ")", ")", ";", "List", "composites", "=", "getIncludedGlyphs", "(", "in", ",", "(", "int", ")", "entry", ".", "getOffset", "(", ")", ",", "origIndex", ")", ";", "// Iterate through all composites pointed to", "// by this composite and check if they exists", "// in the glyphs map, add them if not.", "Iterator", "cps", "=", "composites", ".", "iterator", "(", ")", ";", "while", "(", "cps", ".", "hasNext", "(", ")", ")", "{", "Integer", "cIdx", "=", "(", "Integer", ")", "cps", ".", "next", "(", ")", ";", "if", "(", "glyphs", ".", "get", "(", "cIdx", ")", "==", "null", "&&", "newComposites", ".", "get", "(", "cIdx", ")", "==", "null", ")", "{", "newComposites", ".", "put", "(", "cIdx", ",", "new", "Integer", "(", "newIndex", ")", ")", ";", "newIndex", "++", ";", "}", "}", "}", "}", "// Add composites to glyphs", "Iterator", "m", "=", "newComposites", ".", "keySet", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "m", ".", "hasNext", "(", ")", ")", "{", "Integer", "im", "=", "(", "Integer", ")", "m", ".", "next", "(", ")", ";", "glyphs", ".", "put", "(", "im", ",", "newComposites", ".", "get", "(", "im", ")", ")", ";", "}", "}", "// Iterate through all composites to remap their composite index", "Iterator", "ce", "=", "allComposites", ".", "keySet", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "ce", ".", "hasNext", "(", ")", ")", "{", "remapComposite", "(", "in", ",", "glyphs", ",", "(", "int", ")", "entry", ".", "getOffset", "(", ")", ",", "(", "Integer", ")", "ce", ".", "next", "(", ")", ")", ";", "}", "}", "else", "{", "throw", "new", "IOException", "(", "\"Can't find glyf table\"", ")", ";", "}", "}" ]
Scan all the original glyphs for composite glyphs and add those glyphs to the glyphmapping also rewrite the composite glyph pointers to the new mapping @param in The input stream to read the glyphs from @param glyphs The glyphs map to populate @throws IOException Indicates a failure to read from the reader
[ "Scan", "all", "the", "original", "glyphs", "for", "composite", "glyphs", "and", "add", "those", "glyphs", "to", "the", "glyphmapping", "also", "rewrite", "the", "composite", "glyph", "pointers", "to", "the", "new", "mapping" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L631-L690
1,738
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.readFont
public byte[] readFont(FontFileReader in, String name, Map glyphs) throws IOException { //Check if TrueType collection, and that the name exists in the collection if (!checkTTC(in, name)) { throw new IOException("Failed to read font"); } output = new byte[in.getFileSize()]; readDirTabs(in); readFontHeader(in); getNumGlyphs(in); readHorizontalHeader(in); readHorizontalMetrics(in); readIndexToLocation(in); scanGlyphs(in, glyphs); createDirectory(); // Create the TrueType header and directory createHead(in); createHhea(in, glyphs.size()); // Create the hhea table createHmtx(in, glyphs); // Create hmtx table createMaxp(in, glyphs.size()); // copy the maxp table try { createCvt(in); // copy the cvt table } catch (IOException ex) { // Cvt is optional (only required for OpenType (MS) fonts) //log.error("TrueType warning: " + ex.getMessage()); } try { createFpgm(in); // copy fpgm table } catch (IOException ex) { // Fpgm is optional (only required for OpenType (MS) fonts) //log.error("TrueType warning: " + ex.getMessage()); } try { createPrep(in); // copy prep table } catch (IOException ex) { // Prep is optional (only required for OpenType (MS) fonts) //log.error("TrueType warning: " + ex.getMessage()); } try { createLoca(glyphs.size()); // create empty loca table } catch (IOException ex) { // Loca is optional (only required for OpenType (MS) fonts) //log.error("TrueType warning: " + ex.getMessage()); } try { createGlyf(in, glyphs); } catch (IOException ex) { // Glyf is optional (only required for OpenType (MS) fonts) //log.error("TrueType warning: " + ex.getMessage()); } pad4(); createCheckSumAdjustment(); byte[] ret = new byte[realSize]; System.arraycopy(output, 0, ret, 0, realSize); return ret; }
java
public byte[] readFont(FontFileReader in, String name, Map glyphs) throws IOException { //Check if TrueType collection, and that the name exists in the collection if (!checkTTC(in, name)) { throw new IOException("Failed to read font"); } output = new byte[in.getFileSize()]; readDirTabs(in); readFontHeader(in); getNumGlyphs(in); readHorizontalHeader(in); readHorizontalMetrics(in); readIndexToLocation(in); scanGlyphs(in, glyphs); createDirectory(); // Create the TrueType header and directory createHead(in); createHhea(in, glyphs.size()); // Create the hhea table createHmtx(in, glyphs); // Create hmtx table createMaxp(in, glyphs.size()); // copy the maxp table try { createCvt(in); // copy the cvt table } catch (IOException ex) { // Cvt is optional (only required for OpenType (MS) fonts) //log.error("TrueType warning: " + ex.getMessage()); } try { createFpgm(in); // copy fpgm table } catch (IOException ex) { // Fpgm is optional (only required for OpenType (MS) fonts) //log.error("TrueType warning: " + ex.getMessage()); } try { createPrep(in); // copy prep table } catch (IOException ex) { // Prep is optional (only required for OpenType (MS) fonts) //log.error("TrueType warning: " + ex.getMessage()); } try { createLoca(glyphs.size()); // create empty loca table } catch (IOException ex) { // Loca is optional (only required for OpenType (MS) fonts) //log.error("TrueType warning: " + ex.getMessage()); } try { createGlyf(in, glyphs); } catch (IOException ex) { // Glyf is optional (only required for OpenType (MS) fonts) //log.error("TrueType warning: " + ex.getMessage()); } pad4(); createCheckSumAdjustment(); byte[] ret = new byte[realSize]; System.arraycopy(output, 0, ret, 0, realSize); return ret; }
[ "public", "byte", "[", "]", "readFont", "(", "FontFileReader", "in", ",", "String", "name", ",", "Map", "glyphs", ")", "throws", "IOException", "{", "//Check if TrueType collection, and that the name exists in the collection", "if", "(", "!", "checkTTC", "(", "in", ",", "name", ")", ")", "{", "throw", "new", "IOException", "(", "\"Failed to read font\"", ")", ";", "}", "output", "=", "new", "byte", "[", "in", ".", "getFileSize", "(", ")", "]", ";", "readDirTabs", "(", "in", ")", ";", "readFontHeader", "(", "in", ")", ";", "getNumGlyphs", "(", "in", ")", ";", "readHorizontalHeader", "(", "in", ")", ";", "readHorizontalMetrics", "(", "in", ")", ";", "readIndexToLocation", "(", "in", ")", ";", "scanGlyphs", "(", "in", ",", "glyphs", ")", ";", "createDirectory", "(", ")", ";", "// Create the TrueType header and directory", "createHead", "(", "in", ")", ";", "createHhea", "(", "in", ",", "glyphs", ".", "size", "(", ")", ")", ";", "// Create the hhea table", "createHmtx", "(", "in", ",", "glyphs", ")", ";", "// Create hmtx table", "createMaxp", "(", "in", ",", "glyphs", ".", "size", "(", ")", ")", ";", "// copy the maxp table", "try", "{", "createCvt", "(", "in", ")", ";", "// copy the cvt table", "}", "catch", "(", "IOException", "ex", ")", "{", "// Cvt is optional (only required for OpenType (MS) fonts)", "//log.error(\"TrueType warning: \" + ex.getMessage());", "}", "try", "{", "createFpgm", "(", "in", ")", ";", "// copy fpgm table", "}", "catch", "(", "IOException", "ex", ")", "{", "// Fpgm is optional (only required for OpenType (MS) fonts)", "//log.error(\"TrueType warning: \" + ex.getMessage());", "}", "try", "{", "createPrep", "(", "in", ")", ";", "// copy prep table", "}", "catch", "(", "IOException", "ex", ")", "{", "// Prep is optional (only required for OpenType (MS) fonts)", "//log.error(\"TrueType warning: \" + ex.getMessage());", "}", "try", "{", "createLoca", "(", "glyphs", ".", "size", "(", ")", ")", ";", "// create empty loca table", "}", "catch", "(", "IOException", "ex", ")", "{", "// Loca is optional (only required for OpenType (MS) fonts)", "//log.error(\"TrueType warning: \" + ex.getMessage());", "}", "try", "{", "createGlyf", "(", "in", ",", "glyphs", ")", ";", "}", "catch", "(", "IOException", "ex", ")", "{", "// Glyf is optional (only required for OpenType (MS) fonts)", "//log.error(\"TrueType warning: \" + ex.getMessage());", "}", "pad4", "(", ")", ";", "createCheckSumAdjustment", "(", ")", ";", "byte", "[", "]", "ret", "=", "new", "byte", "[", "realSize", "]", ";", "System", ".", "arraycopy", "(", "output", ",", "0", ",", "ret", ",", "0", ",", "realSize", ")", ";", "return", "ret", ";", "}" ]
Returns a subset of the original font. @param in FontFileReader to read from @param name Name to be checked for in the font file @param glyphs Map of glyphs (glyphs has old index as (Integer) key and new index as (Integer) value) @return A subset of the original font @throws IOException in case of an I/O problem
[ "Returns", "a", "subset", "of", "the", "original", "font", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L704-L772
1,739
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.writeUShort
private void writeUShort(int s) { byte b1 = (byte)((s >> 8) & 0xff); byte b2 = (byte)(s & 0xff); writeByte(b1); writeByte(b2); }
java
private void writeUShort(int s) { byte b1 = (byte)((s >> 8) & 0xff); byte b2 = (byte)(s & 0xff); writeByte(b1); writeByte(b2); }
[ "private", "void", "writeUShort", "(", "int", "s", ")", "{", "byte", "b1", "=", "(", "byte", ")", "(", "(", "s", ">>", "8", ")", "&", "0xff", ")", ";", "byte", "b2", "=", "(", "byte", ")", "(", "s", "&", "0xff", ")", ";", "writeByte", "(", "b1", ")", ";", "writeByte", "(", "b2", ")", ";", "}" ]
Appends a USHORT to the output array, updates currentPost but not realSize @param s The short to write
[ "Appends", "a", "USHORT", "to", "the", "output", "array", "updates", "currentPost", "but", "not", "realSize" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L811-L816
1,740
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.writeUShort
private void writeUShort(int pos, int s) { byte b1 = (byte)((s >> 8) & 0xff); byte b2 = (byte)(s & 0xff); output[pos] = b1; output[pos + 1] = b2; }
java
private void writeUShort(int pos, int s) { byte b1 = (byte)((s >> 8) & 0xff); byte b2 = (byte)(s & 0xff); output[pos] = b1; output[pos + 1] = b2; }
[ "private", "void", "writeUShort", "(", "int", "pos", ",", "int", "s", ")", "{", "byte", "b1", "=", "(", "byte", ")", "(", "(", "s", ">>", "8", ")", "&", "0xff", ")", ";", "byte", "b2", "=", "(", "byte", ")", "(", "s", "&", "0xff", ")", ";", "output", "[", "pos", "]", "=", "b1", ";", "output", "[", "pos", "+", "1", "]", "=", "b2", ";", "}" ]
Appends a USHORT to the output array, at the given position without changing currentPos @param pos The position to write to @param s The short to be written
[ "Appends", "a", "USHORT", "to", "the", "output", "array", "at", "the", "given", "position", "without", "changing", "currentPos" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L825-L830
1,741
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.writeULong
private void writeULong(int s) { byte b1 = (byte)((s >> 24) & 0xff); byte b2 = (byte)((s >> 16) & 0xff); byte b3 = (byte)((s >> 8) & 0xff); byte b4 = (byte)(s & 0xff); writeByte(b1); writeByte(b2); writeByte(b3); writeByte(b4); }
java
private void writeULong(int s) { byte b1 = (byte)((s >> 24) & 0xff); byte b2 = (byte)((s >> 16) & 0xff); byte b3 = (byte)((s >> 8) & 0xff); byte b4 = (byte)(s & 0xff); writeByte(b1); writeByte(b2); writeByte(b3); writeByte(b4); }
[ "private", "void", "writeULong", "(", "int", "s", ")", "{", "byte", "b1", "=", "(", "byte", ")", "(", "(", "s", ">>", "24", ")", "&", "0xff", ")", ";", "byte", "b2", "=", "(", "byte", ")", "(", "(", "s", ">>", "16", ")", "&", "0xff", ")", ";", "byte", "b3", "=", "(", "byte", ")", "(", "(", "s", ">>", "8", ")", "&", "0xff", ")", ";", "byte", "b4", "=", "(", "byte", ")", "(", "s", "&", "0xff", ")", ";", "writeByte", "(", "b1", ")", ";", "writeByte", "(", "b2", ")", ";", "writeByte", "(", "b3", ")", ";", "writeByte", "(", "b4", ")", ";", "}" ]
Appends a ULONG to the output array, updates currentPos but not realSize @param s The value to write
[ "Appends", "a", "ULONG", "to", "the", "output", "array", "updates", "currentPos", "but", "not", "realSize" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L838-L847
1,742
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.readUShort
private int readUShort(int pos) { int ret = output[pos]; if (ret < 0) { ret += 256; } ret = ret << 8; if (output[pos + 1] < 0) { ret |= output[pos + 1] + 256; } else { ret |= output[pos + 1]; } return ret; }
java
private int readUShort(int pos) { int ret = output[pos]; if (ret < 0) { ret += 256; } ret = ret << 8; if (output[pos + 1] < 0) { ret |= output[pos + 1] + 256; } else { ret |= output[pos + 1]; } return ret; }
[ "private", "int", "readUShort", "(", "int", "pos", ")", "{", "int", "ret", "=", "output", "[", "pos", "]", ";", "if", "(", "ret", "<", "0", ")", "{", "ret", "+=", "256", ";", "}", "ret", "=", "ret", "<<", "8", ";", "if", "(", "output", "[", "pos", "+", "1", "]", "<", "0", ")", "{", "ret", "|=", "output", "[", "pos", "+", "1", "]", "+", "256", ";", "}", "else", "{", "ret", "|=", "output", "[", "pos", "+", "1", "]", ";", "}", "return", "ret", ";", "}" ]
Read a unsigned short value at given position @param pos The position from the file to read @return The short read
[ "Read", "a", "unsigned", "short", "value", "at", "given", "position" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L885-L898
1,743
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.pad4
private void pad4() { int padSize = currentPos % 4; for (int i = 0; i < padSize; i++) { output[currentPos++] = 0; realSize++; } }
java
private void pad4() { int padSize = currentPos % 4; for (int i = 0; i < padSize; i++) { output[currentPos++] = 0; realSize++; } }
[ "private", "void", "pad4", "(", ")", "{", "int", "padSize", "=", "currentPos", "%", "4", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "padSize", ";", "i", "++", ")", "{", "output", "[", "currentPos", "++", "]", "=", "0", ";", "realSize", "++", ";", "}", "}" ]
Create a padding in the fontfile to align on a 4-byte boundary
[ "Create", "a", "padding", "in", "the", "fontfile", "to", "align", "on", "a", "4", "-", "byte", "boundary" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L904-L910
1,744
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java
TTFSubSetFile.getLongCheckSum
private long getLongCheckSum(int start, int size) { // All the tables here are aligned on four byte boundaries // Add remainder to size if it's not a multiple of 4 int remainder = size % 4; if (remainder != 0) { size += remainder; } long sum = 0; for (int i = 0; i < size; i += 4) { int l = (output[start + i] << 24); l += (output[start + i + 1] << 16); l += (output[start + i + 2] << 16); l += (output[start + i + 3] << 16); sum += l; if (sum > 0xffffffff) { sum = sum - 0xffffffff; } } return sum; }
java
private long getLongCheckSum(int start, int size) { // All the tables here are aligned on four byte boundaries // Add remainder to size if it's not a multiple of 4 int remainder = size % 4; if (remainder != 0) { size += remainder; } long sum = 0; for (int i = 0; i < size; i += 4) { int l = (output[start + i] << 24); l += (output[start + i + 1] << 16); l += (output[start + i + 2] << 16); l += (output[start + i + 3] << 16); sum += l; if (sum > 0xffffffff) { sum = sum - 0xffffffff; } } return sum; }
[ "private", "long", "getLongCheckSum", "(", "int", "start", ",", "int", "size", ")", "{", "// All the tables here are aligned on four byte boundaries", "// Add remainder to size if it's not a multiple of 4", "int", "remainder", "=", "size", "%", "4", ";", "if", "(", "remainder", "!=", "0", ")", "{", "size", "+=", "remainder", ";", "}", "long", "sum", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "size", ";", "i", "+=", "4", ")", "{", "int", "l", "=", "(", "output", "[", "start", "+", "i", "]", "<<", "24", ")", ";", "l", "+=", "(", "output", "[", "start", "+", "i", "+", "1", "]", "<<", "16", ")", ";", "l", "+=", "(", "output", "[", "start", "+", "i", "+", "2", "]", "<<", "16", ")", ";", "l", "+=", "(", "output", "[", "start", "+", "i", "+", "3", "]", "<<", "16", ")", ";", "sum", "+=", "l", ";", "if", "(", "sum", ">", "0xffffffff", ")", "{", "sum", "=", "sum", "-", "0xffffffff", ";", "}", "}", "return", "sum", ";", "}" ]
Get the checksum as a long @param start The start value @param size The size of the values to checksum @return The long checksum
[ "Get", "the", "checksum", "as", "a", "long" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFSubSetFile.java#L956-L978
1,745
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/gui/TextField.java
TextField.setText
public void setText(String value) { this.value = value; if (cursorPos > value.length()) { cursorPos = value.length(); } }
java
public void setText(String value) { this.value = value; if (cursorPos > value.length()) { cursorPos = value.length(); } }
[ "public", "void", "setText", "(", "String", "value", ")", "{", "this", ".", "value", "=", "value", ";", "if", "(", "cursorPos", ">", "value", ".", "length", "(", ")", ")", "{", "cursorPos", "=", "value", ".", "length", "(", ")", ";", "}", "}" ]
Set the value to be displayed in the text field @param value The value to be displayed in the text field
[ "Set", "the", "value", "to", "be", "displayed", "in", "the", "text", "field" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/gui/TextField.java#L290-L295
1,746
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/gui/TextField.java
TextField.setCursorPos
public void setCursorPos(int pos) { cursorPos = pos; if (cursorPos > value.length()) { cursorPos = value.length(); } }
java
public void setCursorPos(int pos) { cursorPos = pos; if (cursorPos > value.length()) { cursorPos = value.length(); } }
[ "public", "void", "setCursorPos", "(", "int", "pos", ")", "{", "cursorPos", "=", "pos", ";", "if", "(", "cursorPos", ">", "value", ".", "length", "(", ")", ")", "{", "cursorPos", "=", "value", ".", "length", "(", ")", ";", "}", "}" ]
Set the position of the cursor @param pos The new position of the cursor
[ "Set", "the", "position", "of", "the", "cursor" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/gui/TextField.java#L303-L308
1,747
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/gui/TextField.java
TextField.setMaxLength
public void setMaxLength(int length) { maxCharacter = length; if (value.length() > maxCharacter) { value = value.substring(0, maxCharacter); } }
java
public void setMaxLength(int length) { maxCharacter = length; if (value.length() > maxCharacter) { value = value.substring(0, maxCharacter); } }
[ "public", "void", "setMaxLength", "(", "int", "length", ")", "{", "maxCharacter", "=", "length", ";", "if", "(", "value", ".", "length", "(", ")", ">", "maxCharacter", ")", "{", "value", "=", "value", ".", "substring", "(", "0", ",", "maxCharacter", ")", ";", "}", "}" ]
Set the length of the allowed input @param length The length of the allowed input
[ "Set", "the", "length", "of", "the", "allowed", "input" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/gui/TextField.java#L326-L331
1,748
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/gui/TextField.java
TextField.doPaste
protected void doPaste(String text) { recordOldPosition(); for (int i=0;i<text.length();i++) { keyPressed(-1, text.charAt(i)); } }
java
protected void doPaste(String text) { recordOldPosition(); for (int i=0;i<text.length();i++) { keyPressed(-1, text.charAt(i)); } }
[ "protected", "void", "doPaste", "(", "String", "text", ")", "{", "recordOldPosition", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "text", ".", "length", "(", ")", ";", "i", "++", ")", "{", "keyPressed", "(", "-", "1", ",", "text", ".", "charAt", "(", "i", ")", ")", ";", "}", "}" ]
Do the paste into the field, overrideable for custom behaviour @param text The text to be pasted in
[ "Do", "the", "paste", "into", "the", "field", "overrideable", "for", "custom", "behaviour" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/gui/TextField.java#L338-L344
1,749
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/gui/TextField.java
TextField.doUndo
protected void doUndo(int oldCursorPos, String oldText) { if (oldText != null) { setText(oldText); setCursorPos(oldCursorPos); } }
java
protected void doUndo(int oldCursorPos, String oldText) { if (oldText != null) { setText(oldText); setCursorPos(oldCursorPos); } }
[ "protected", "void", "doUndo", "(", "int", "oldCursorPos", ",", "String", "oldText", ")", "{", "if", "(", "oldText", "!=", "null", ")", "{", "setText", "(", "oldText", ")", ";", "setCursorPos", "(", "oldCursorPos", ")", ";", "}", "}" ]
Do the undo of the paste, overrideable for custom behaviour @param oldCursorPos before the paste @param oldText The text before the last paste
[ "Do", "the", "undo", "of", "the", "paste", "overrideable", "for", "custom", "behaviour" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/gui/TextField.java#L360-L365
1,750
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java
FontData.getPlain
public static FontData getPlain(String familyName) { FontData data = (FontData) plain.get(familyName); return data; }
java
public static FontData getPlain(String familyName) { FontData data = (FontData) plain.get(familyName); return data; }
[ "public", "static", "FontData", "getPlain", "(", "String", "familyName", ")", "{", "FontData", "data", "=", "(", "FontData", ")", "plain", ".", "get", "(", "familyName", ")", ";", "return", "data", ";", "}" ]
Get the plain version of a family name @param familyName The font family to retrieve @return The plain version of the font or null if no plain version exits
[ "Get", "the", "plain", "version", "of", "a", "family", "name" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java#L101-L105
1,751
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java
FontData.getBold
public static FontData getBold(String familyName) { FontData data = (FontData) bold.get(familyName); return data; }
java
public static FontData getBold(String familyName) { FontData data = (FontData) bold.get(familyName); return data; }
[ "public", "static", "FontData", "getBold", "(", "String", "familyName", ")", "{", "FontData", "data", "=", "(", "FontData", ")", "bold", ".", "get", "(", "familyName", ")", ";", "return", "data", ";", "}" ]
Get the bold version of the font @param familyName The name of the font family @return The bold version of the font or null if no bold version exists
[ "Get", "the", "bold", "version", "of", "the", "font" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java#L113-L117
1,752
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java
FontData.getBoldItalic
public static FontData getBoldItalic(String familyName) { FontData data = (FontData) bolditalic.get(familyName); return data; }
java
public static FontData getBoldItalic(String familyName) { FontData data = (FontData) bolditalic.get(familyName); return data; }
[ "public", "static", "FontData", "getBoldItalic", "(", "String", "familyName", ")", "{", "FontData", "data", "=", "(", "FontData", ")", "bolditalic", ".", "get", "(", "familyName", ")", ";", "return", "data", ";", "}" ]
Get the bold italic version of the font @param familyName The name of the font family @return The bold italic version of the font or null if no bold italic version exists
[ "Get", "the", "bold", "italic", "version", "of", "the", "font" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java#L125-L129
1,753
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java
FontData.getItalic
public static FontData getItalic(String familyName) { FontData data = (FontData) italic.get(familyName); return data; }
java
public static FontData getItalic(String familyName) { FontData data = (FontData) italic.get(familyName); return data; }
[ "public", "static", "FontData", "getItalic", "(", "String", "familyName", ")", "{", "FontData", "data", "=", "(", "FontData", ")", "italic", ".", "get", "(", "familyName", ")", ";", "return", "data", ";", "}" ]
Get the italic version of the font @param familyName The name of the font family @return The italic version of the font or null if no italic version exists
[ "Get", "the", "italic", "version", "of", "the", "font" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java#L137-L141
1,754
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java
FontData.getStyled
public static FontData getStyled(String familyName, int style) { boolean b = (style & Font.BOLD) != 0; boolean i = (style & Font.ITALIC) != 0; if (b & i) { return getBoldItalic(familyName); } else if (b) { return getBold(familyName); } else if (i) { return getItalic(familyName); } else { return getPlain(familyName); } }
java
public static FontData getStyled(String familyName, int style) { boolean b = (style & Font.BOLD) != 0; boolean i = (style & Font.ITALIC) != 0; if (b & i) { return getBoldItalic(familyName); } else if (b) { return getBold(familyName); } else if (i) { return getItalic(familyName); } else { return getPlain(familyName); } }
[ "public", "static", "FontData", "getStyled", "(", "String", "familyName", ",", "int", "style", ")", "{", "boolean", "b", "=", "(", "style", "&", "Font", ".", "BOLD", ")", "!=", "0", ";", "boolean", "i", "=", "(", "style", "&", "Font", ".", "ITALIC", ")", "!=", "0", ";", "if", "(", "b", "&", "i", ")", "{", "return", "getBoldItalic", "(", "familyName", ")", ";", "}", "else", "if", "(", "b", ")", "{", "return", "getBold", "(", "familyName", ")", ";", "}", "else", "if", "(", "i", ")", "{", "return", "getItalic", "(", "familyName", ")", ";", "}", "else", "{", "return", "getPlain", "(", "familyName", ")", ";", "}", "}" ]
Get a styled version of a particular font family @param familyName The name of the font family @param style The style (@see java.awt.Font#PLAIN) @return The styled font or null if no such font exists
[ "Get", "a", "styled", "version", "of", "a", "particular", "font", "family" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java#L150-L163
1,755
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java
FontData.processFontDirectory
private static void processFontDirectory(File dir, ArrayList fonts) { if (!dir.exists()) { return; } if (processed.contains(dir)) { return; } processed.add(dir); File[] sources = dir.listFiles(); if (sources == null) { return; } for (int j=0;j<sources.length;j++) { File source = sources[j]; if (source.getName().equals(".")) { continue; } if (source.getName().equals("..")) { continue; } if (source.isDirectory()) { processFontDirectory(source, fonts); continue; } if (source.getName().toLowerCase().endsWith(".ttf")) { try { if (statusListener != null) { statusListener.updateStatus("Processing "+source.getName()); } FontData data = new FontData(new FileInputStream(source), 1); fonts.add(data); String famName = data.getFamilyName(); if (!families.contains(famName)) { families.add(famName); } boolean bo = data.getJavaFont().isBold(); boolean it = data.getJavaFont().isItalic(); if ((bo) && (it)) { bolditalic.put(famName, data); } else if (bo) { bold.put(famName, data); } else if (it) { italic.put(famName, data); } else { plain.put(famName, data); } } catch (Exception e) { if (DEBUG) { System.err.println("Unable to process: "+source.getAbsolutePath()+" ("+e.getClass()+": "+e.getMessage()+")"); } if (statusListener != null) { statusListener.updateStatus("Unable to process: "+source.getName()); } } } } }
java
private static void processFontDirectory(File dir, ArrayList fonts) { if (!dir.exists()) { return; } if (processed.contains(dir)) { return; } processed.add(dir); File[] sources = dir.listFiles(); if (sources == null) { return; } for (int j=0;j<sources.length;j++) { File source = sources[j]; if (source.getName().equals(".")) { continue; } if (source.getName().equals("..")) { continue; } if (source.isDirectory()) { processFontDirectory(source, fonts); continue; } if (source.getName().toLowerCase().endsWith(".ttf")) { try { if (statusListener != null) { statusListener.updateStatus("Processing "+source.getName()); } FontData data = new FontData(new FileInputStream(source), 1); fonts.add(data); String famName = data.getFamilyName(); if (!families.contains(famName)) { families.add(famName); } boolean bo = data.getJavaFont().isBold(); boolean it = data.getJavaFont().isItalic(); if ((bo) && (it)) { bolditalic.put(famName, data); } else if (bo) { bold.put(famName, data); } else if (it) { italic.put(famName, data); } else { plain.put(famName, data); } } catch (Exception e) { if (DEBUG) { System.err.println("Unable to process: "+source.getAbsolutePath()+" ("+e.getClass()+": "+e.getMessage()+")"); } if (statusListener != null) { statusListener.updateStatus("Unable to process: "+source.getName()); } } } } }
[ "private", "static", "void", "processFontDirectory", "(", "File", "dir", ",", "ArrayList", "fonts", ")", "{", "if", "(", "!", "dir", ".", "exists", "(", ")", ")", "{", "return", ";", "}", "if", "(", "processed", ".", "contains", "(", "dir", ")", ")", "{", "return", ";", "}", "processed", ".", "add", "(", "dir", ")", ";", "File", "[", "]", "sources", "=", "dir", ".", "listFiles", "(", ")", ";", "if", "(", "sources", "==", "null", ")", "{", "return", ";", "}", "for", "(", "int", "j", "=", "0", ";", "j", "<", "sources", ".", "length", ";", "j", "++", ")", "{", "File", "source", "=", "sources", "[", "j", "]", ";", "if", "(", "source", ".", "getName", "(", ")", ".", "equals", "(", "\".\"", ")", ")", "{", "continue", ";", "}", "if", "(", "source", ".", "getName", "(", ")", ".", "equals", "(", "\"..\"", ")", ")", "{", "continue", ";", "}", "if", "(", "source", ".", "isDirectory", "(", ")", ")", "{", "processFontDirectory", "(", "source", ",", "fonts", ")", ";", "continue", ";", "}", "if", "(", "source", ".", "getName", "(", ")", ".", "toLowerCase", "(", ")", ".", "endsWith", "(", "\".ttf\"", ")", ")", "{", "try", "{", "if", "(", "statusListener", "!=", "null", ")", "{", "statusListener", ".", "updateStatus", "(", "\"Processing \"", "+", "source", ".", "getName", "(", ")", ")", ";", "}", "FontData", "data", "=", "new", "FontData", "(", "new", "FileInputStream", "(", "source", ")", ",", "1", ")", ";", "fonts", ".", "add", "(", "data", ")", ";", "String", "famName", "=", "data", ".", "getFamilyName", "(", ")", ";", "if", "(", "!", "families", ".", "contains", "(", "famName", ")", ")", "{", "families", ".", "add", "(", "famName", ")", ";", "}", "boolean", "bo", "=", "data", ".", "getJavaFont", "(", ")", ".", "isBold", "(", ")", ";", "boolean", "it", "=", "data", ".", "getJavaFont", "(", ")", ".", "isItalic", "(", ")", ";", "if", "(", "(", "bo", ")", "&&", "(", "it", ")", ")", "{", "bolditalic", ".", "put", "(", "famName", ",", "data", ")", ";", "}", "else", "if", "(", "bo", ")", "{", "bold", ".", "put", "(", "famName", ",", "data", ")", ";", "}", "else", "if", "(", "it", ")", "{", "italic", ".", "put", "(", "famName", ",", "data", ")", ";", "}", "else", "{", "plain", ".", "put", "(", "famName", ",", "data", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "if", "(", "DEBUG", ")", "{", "System", ".", "err", ".", "println", "(", "\"Unable to process: \"", "+", "source", ".", "getAbsolutePath", "(", ")", "+", "\" (\"", "+", "e", ".", "getClass", "(", ")", "+", "\": \"", "+", "e", ".", "getMessage", "(", ")", "+", "\")\"", ")", ";", "}", "if", "(", "statusListener", "!=", "null", ")", "{", "statusListener", ".", "updateStatus", "(", "\"Unable to process: \"", "+", "source", ".", "getName", "(", ")", ")", ";", "}", "}", "}", "}", "}" ]
Process a directory potentially full of fonts @param dir The directory of fonts to process @param fonts The fonts list to add to
[ "Process", "a", "directory", "potentially", "full", "of", "fonts" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java#L171-L233
1,756
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java
FontData.getAllFonts
public static FontData[] getAllFonts() { if (fonts == null) { fonts = new ArrayList(); String os = System.getProperty("os.name"); File[] locs = new File[0]; if (os.startsWith("Windows")) { locs = win32; } if (os.startsWith("Linux")) { locs = linux; } if (os.startsWith("Mac OS")) { locs = macos; } for (int i=0;i<locs.length;i++) { File loc = locs[i]; processFontDirectory(loc, fonts); } if (os.startsWith("Linux")) { locateLinuxFonts(new File("/etc/fonts/fonts.conf")); } } return (FontData[]) fonts.toArray(new FontData[0]); }
java
public static FontData[] getAllFonts() { if (fonts == null) { fonts = new ArrayList(); String os = System.getProperty("os.name"); File[] locs = new File[0]; if (os.startsWith("Windows")) { locs = win32; } if (os.startsWith("Linux")) { locs = linux; } if (os.startsWith("Mac OS")) { locs = macos; } for (int i=0;i<locs.length;i++) { File loc = locs[i]; processFontDirectory(loc, fonts); } if (os.startsWith("Linux")) { locateLinuxFonts(new File("/etc/fonts/fonts.conf")); } } return (FontData[]) fonts.toArray(new FontData[0]); }
[ "public", "static", "FontData", "[", "]", "getAllFonts", "(", ")", "{", "if", "(", "fonts", "==", "null", ")", "{", "fonts", "=", "new", "ArrayList", "(", ")", ";", "String", "os", "=", "System", ".", "getProperty", "(", "\"os.name\"", ")", ";", "File", "[", "]", "locs", "=", "new", "File", "[", "0", "]", ";", "if", "(", "os", ".", "startsWith", "(", "\"Windows\"", ")", ")", "{", "locs", "=", "win32", ";", "}", "if", "(", "os", ".", "startsWith", "(", "\"Linux\"", ")", ")", "{", "locs", "=", "linux", ";", "}", "if", "(", "os", ".", "startsWith", "(", "\"Mac OS\"", ")", ")", "{", "locs", "=", "macos", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "locs", ".", "length", ";", "i", "++", ")", "{", "File", "loc", "=", "locs", "[", "i", "]", ";", "processFontDirectory", "(", "loc", ",", "fonts", ")", ";", "}", "if", "(", "os", ".", "startsWith", "(", "\"Linux\"", ")", ")", "{", "locateLinuxFonts", "(", "new", "File", "(", "\"/etc/fonts/fonts.conf\"", ")", ")", ";", "}", "}", "return", "(", "FontData", "[", "]", ")", "fonts", ".", "toArray", "(", "new", "FontData", "[", "0", "]", ")", ";", "}" ]
Get all the fonts available @return The list of fonts available
[ "Get", "all", "the", "fonts", "available" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java#L240-L270
1,757
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java
FontData.locateLinuxFonts
private static void locateLinuxFonts(File file) { if (!file.exists()) { System.err.println("Unable to open: "+file.getAbsolutePath()); return; } try { InputStream in = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); ByteArrayOutputStream temp = new ByteArrayOutputStream(); PrintStream pout = new PrintStream(temp); while (reader.ready()) { String line = reader.readLine(); if (line.indexOf("DOCTYPE") == -1) { pout.println(line); } } in = new ByteArrayInputStream(temp.toByteArray()); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(in); NodeList dirs = document.getElementsByTagName("dir"); for (int i=0;i<dirs.getLength();i++) { Element element = (Element) dirs.item(i); String dir = element.getFirstChild().getNodeValue(); if (dir.startsWith("~")) { dir = dir.substring(1); dir = userhome + dir; } addFontDirectory(new File(dir)); } NodeList includes = document.getElementsByTagName("include"); for (int i=0;i<includes.getLength();i++) { Element element = (Element) dirs.item(i); String inc = element.getFirstChild().getNodeValue(); if (inc.startsWith("~")) { inc = inc.substring(1); inc = userhome + inc; } locateLinuxFonts(new File(inc)); } } catch (Exception e) { e.printStackTrace(); System.err.println("Unable to process: "+file.getAbsolutePath()); } }
java
private static void locateLinuxFonts(File file) { if (!file.exists()) { System.err.println("Unable to open: "+file.getAbsolutePath()); return; } try { InputStream in = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); ByteArrayOutputStream temp = new ByteArrayOutputStream(); PrintStream pout = new PrintStream(temp); while (reader.ready()) { String line = reader.readLine(); if (line.indexOf("DOCTYPE") == -1) { pout.println(line); } } in = new ByteArrayInputStream(temp.toByteArray()); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(in); NodeList dirs = document.getElementsByTagName("dir"); for (int i=0;i<dirs.getLength();i++) { Element element = (Element) dirs.item(i); String dir = element.getFirstChild().getNodeValue(); if (dir.startsWith("~")) { dir = dir.substring(1); dir = userhome + dir; } addFontDirectory(new File(dir)); } NodeList includes = document.getElementsByTagName("include"); for (int i=0;i<includes.getLength();i++) { Element element = (Element) dirs.item(i); String inc = element.getFirstChild().getNodeValue(); if (inc.startsWith("~")) { inc = inc.substring(1); inc = userhome + inc; } locateLinuxFonts(new File(inc)); } } catch (Exception e) { e.printStackTrace(); System.err.println("Unable to process: "+file.getAbsolutePath()); } }
[ "private", "static", "void", "locateLinuxFonts", "(", "File", "file", ")", "{", "if", "(", "!", "file", ".", "exists", "(", ")", ")", "{", "System", ".", "err", ".", "println", "(", "\"Unable to open: \"", "+", "file", ".", "getAbsolutePath", "(", ")", ")", ";", "return", ";", "}", "try", "{", "InputStream", "in", "=", "new", "FileInputStream", "(", "file", ")", ";", "BufferedReader", "reader", "=", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "in", ")", ")", ";", "ByteArrayOutputStream", "temp", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "PrintStream", "pout", "=", "new", "PrintStream", "(", "temp", ")", ";", "while", "(", "reader", ".", "ready", "(", ")", ")", "{", "String", "line", "=", "reader", ".", "readLine", "(", ")", ";", "if", "(", "line", ".", "indexOf", "(", "\"DOCTYPE\"", ")", "==", "-", "1", ")", "{", "pout", ".", "println", "(", "line", ")", ";", "}", "}", "in", "=", "new", "ByteArrayInputStream", "(", "temp", ".", "toByteArray", "(", ")", ")", ";", "DocumentBuilderFactory", "factory", "=", "DocumentBuilderFactory", ".", "newInstance", "(", ")", ";", "DocumentBuilder", "builder", "=", "factory", ".", "newDocumentBuilder", "(", ")", ";", "Document", "document", "=", "builder", ".", "parse", "(", "in", ")", ";", "NodeList", "dirs", "=", "document", ".", "getElementsByTagName", "(", "\"dir\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dirs", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Element", "element", "=", "(", "Element", ")", "dirs", ".", "item", "(", "i", ")", ";", "String", "dir", "=", "element", ".", "getFirstChild", "(", ")", ".", "getNodeValue", "(", ")", ";", "if", "(", "dir", ".", "startsWith", "(", "\"~\"", ")", ")", "{", "dir", "=", "dir", ".", "substring", "(", "1", ")", ";", "dir", "=", "userhome", "+", "dir", ";", "}", "addFontDirectory", "(", "new", "File", "(", "dir", ")", ")", ";", "}", "NodeList", "includes", "=", "document", ".", "getElementsByTagName", "(", "\"include\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "includes", ".", "getLength", "(", ")", ";", "i", "++", ")", "{", "Element", "element", "=", "(", "Element", ")", "dirs", ".", "item", "(", "i", ")", ";", "String", "inc", "=", "element", ".", "getFirstChild", "(", ")", ".", "getNodeValue", "(", ")", ";", "if", "(", "inc", ".", "startsWith", "(", "\"~\"", ")", ")", "{", "inc", "=", "inc", ".", "substring", "(", "1", ")", ";", "inc", "=", "userhome", "+", "inc", ";", "}", "locateLinuxFonts", "(", "new", "File", "(", "inc", ")", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "System", ".", "err", ".", "println", "(", "\"Unable to process: \"", "+", "file", ".", "getAbsolutePath", "(", ")", ")", ";", "}", "}" ]
Locate the linux fonts based on the XML configuration file @param file The location of the XML file
[ "Locate", "the", "linux", "fonts", "based", "on", "the", "XML", "configuration", "file" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java#L277-L331
1,758
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java
FontData.deriveFont
public FontData deriveFont(float size, int style) { FontData original = getStyled(getFamilyName(), style); FontData data = new FontData(); data.size = size; data.javaFont = original.javaFont.deriveFont(style, size); data.upem = upem; data.ansiKerning = ansiKerning; data.charWidth = charWidth; return data; }
java
public FontData deriveFont(float size, int style) { FontData original = getStyled(getFamilyName(), style); FontData data = new FontData(); data.size = size; data.javaFont = original.javaFont.deriveFont(style, size); data.upem = upem; data.ansiKerning = ansiKerning; data.charWidth = charWidth; return data; }
[ "public", "FontData", "deriveFont", "(", "float", "size", ",", "int", "style", ")", "{", "FontData", "original", "=", "getStyled", "(", "getFamilyName", "(", ")", ",", "style", ")", ";", "FontData", "data", "=", "new", "FontData", "(", ")", ";", "data", ".", "size", "=", "size", ";", "data", ".", "javaFont", "=", "original", ".", "javaFont", ".", "deriveFont", "(", "style", ",", "size", ")", ";", "data", ".", "upem", "=", "upem", ";", "data", ".", "ansiKerning", "=", "ansiKerning", ";", "data", ".", "charWidth", "=", "charWidth", ";", "return", "data", ";", "}" ]
Derive a new version of this font based on a new size @param size The size of the new font @param style The style of the new font @return The new font data
[ "Derive", "a", "new", "version", "of", "this", "font", "based", "on", "a", "new", "size" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java#L438-L448
1,759
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java
FontData.getKerning
public int getKerning(char first, char second) { Map toMap = (Map) ansiKerning.get(new Integer(first)); if (toMap == null) { return 0; } Integer kerning = (Integer) toMap.get(new Integer(second)); if (kerning == null) { return 0; } return Math.round(convertUnitToEm(size, kerning.intValue())); }
java
public int getKerning(char first, char second) { Map toMap = (Map) ansiKerning.get(new Integer(first)); if (toMap == null) { return 0; } Integer kerning = (Integer) toMap.get(new Integer(second)); if (kerning == null) { return 0; } return Math.round(convertUnitToEm(size, kerning.intValue())); }
[ "public", "int", "getKerning", "(", "char", "first", ",", "char", "second", ")", "{", "Map", "toMap", "=", "(", "Map", ")", "ansiKerning", ".", "get", "(", "new", "Integer", "(", "first", ")", ")", ";", "if", "(", "toMap", "==", "null", ")", "{", "return", "0", ";", "}", "Integer", "kerning", "=", "(", "Integer", ")", "toMap", ".", "get", "(", "new", "Integer", "(", "second", ")", ")", ";", "if", "(", "kerning", "==", "null", ")", "{", "return", "0", ";", "}", "return", "Math", ".", "round", "(", "convertUnitToEm", "(", "size", ",", "kerning", ".", "intValue", "(", ")", ")", ")", ";", "}" ]
Get the kerning value between two characters @param first The first character @param second The second character @return The amount of kerning to apply between the two characters
[ "Get", "the", "kerning", "value", "between", "two", "characters" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/FontData.java#L493-L505
1,760
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/opengl/ImageDataFactory.java
ImageDataFactory.checkProperty
private static void checkProperty() { if (!pngLoaderPropertyChecked) { pngLoaderPropertyChecked = true; try { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { String val = System.getProperty(PNG_LOADER); if ("false".equalsIgnoreCase(val)) { usePngLoader = false; } Log.info("Use Java PNG Loader = " + usePngLoader); return null; } }); } catch (Throwable e) { // ignore, security failure - probably an applet } } }
java
private static void checkProperty() { if (!pngLoaderPropertyChecked) { pngLoaderPropertyChecked = true; try { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { String val = System.getProperty(PNG_LOADER); if ("false".equalsIgnoreCase(val)) { usePngLoader = false; } Log.info("Use Java PNG Loader = " + usePngLoader); return null; } }); } catch (Throwable e) { // ignore, security failure - probably an applet } } }
[ "private", "static", "void", "checkProperty", "(", ")", "{", "if", "(", "!", "pngLoaderPropertyChecked", ")", "{", "pngLoaderPropertyChecked", "=", "true", ";", "try", "{", "AccessController", ".", "doPrivileged", "(", "new", "PrivilegedAction", "(", ")", "{", "public", "Object", "run", "(", ")", "{", "String", "val", "=", "System", ".", "getProperty", "(", "PNG_LOADER", ")", ";", "if", "(", "\"false\"", ".", "equalsIgnoreCase", "(", "val", ")", ")", "{", "usePngLoader", "=", "false", ";", "}", "Log", ".", "info", "(", "\"Use Java PNG Loader = \"", "+", "usePngLoader", ")", ";", "return", "null", ";", "}", "}", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "// ignore, security failure - probably an applet\r", "}", "}", "}" ]
Check PNG loader property. If set the native PNG loader will not be used.
[ "Check", "PNG", "loader", "property", ".", "If", "set", "the", "native", "PNG", "loader", "will", "not", "be", "used", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/opengl/ImageDataFactory.java#L28-L48
1,761
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/opengl/ImageDataFactory.java
ImageDataFactory.getImageDataFor
public static LoadableImageData getImageDataFor(String ref) { LoadableImageData imageData; checkProperty(); ref = ref.toLowerCase(); if (ref.endsWith(".tga")) { return new TGAImageData(); } if (ref.endsWith(".png")) { CompositeImageData data = new CompositeImageData(); if (usePngLoader) { data.add(new PNGImageData()); } data.add(new ImageIOImageData()); return data; } return new ImageIOImageData(); }
java
public static LoadableImageData getImageDataFor(String ref) { LoadableImageData imageData; checkProperty(); ref = ref.toLowerCase(); if (ref.endsWith(".tga")) { return new TGAImageData(); } if (ref.endsWith(".png")) { CompositeImageData data = new CompositeImageData(); if (usePngLoader) { data.add(new PNGImageData()); } data.add(new ImageIOImageData()); return data; } return new ImageIOImageData(); }
[ "public", "static", "LoadableImageData", "getImageDataFor", "(", "String", "ref", ")", "{", "LoadableImageData", "imageData", ";", "checkProperty", "(", ")", ";", "ref", "=", "ref", ".", "toLowerCase", "(", ")", ";", "if", "(", "ref", ".", "endsWith", "(", "\".tga\"", ")", ")", "{", "return", "new", "TGAImageData", "(", ")", ";", "}", "if", "(", "ref", ".", "endsWith", "(", "\".png\"", ")", ")", "{", "CompositeImageData", "data", "=", "new", "CompositeImageData", "(", ")", ";", "if", "(", "usePngLoader", ")", "{", "data", ".", "add", "(", "new", "PNGImageData", "(", ")", ")", ";", "}", "data", ".", "add", "(", "new", "ImageIOImageData", "(", ")", ")", ";", "return", "data", ";", "}", "return", "new", "ImageIOImageData", "(", ")", ";", "}" ]
Create an image data that is appropriate for the reference supplied @param ref The reference to the image to retrieve @return The image data that can be used to retrieve the data for that resource
[ "Create", "an", "image", "data", "that", "is", "appropriate", "for", "the", "reference", "supplied" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/opengl/ImageDataFactory.java#L56-L76
1,762
nguillaumin/slick2d-maven
slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFDirTabEntry.java
TTFDirTabEntry.read
public String read(FontFileReader in) throws IOException { tag[0] = in.readTTFByte(); tag[1] = in.readTTFByte(); tag[2] = in.readTTFByte(); tag[3] = in.readTTFByte(); in.skip(4); // Skip checksum offset = in.readTTFULong(); length = in.readTTFULong(); String tagStr = new String(tag, "ISO-8859-1"); return tagStr; }
java
public String read(FontFileReader in) throws IOException { tag[0] = in.readTTFByte(); tag[1] = in.readTTFByte(); tag[2] = in.readTTFByte(); tag[3] = in.readTTFByte(); in.skip(4); // Skip checksum offset = in.readTTFULong(); length = in.readTTFULong(); String tagStr = new String(tag, "ISO-8859-1"); return tagStr; }
[ "public", "String", "read", "(", "FontFileReader", "in", ")", "throws", "IOException", "{", "tag", "[", "0", "]", "=", "in", ".", "readTTFByte", "(", ")", ";", "tag", "[", "1", "]", "=", "in", ".", "readTTFByte", "(", ")", ";", "tag", "[", "2", "]", "=", "in", ".", "readTTFByte", "(", ")", ";", "tag", "[", "3", "]", "=", "in", ".", "readTTFByte", "(", ")", ";", "in", ".", "skip", "(", "4", ")", ";", "// Skip checksum", "offset", "=", "in", ".", "readTTFULong", "(", ")", ";", "length", "=", "in", ".", "readTTFULong", "(", ")", ";", "String", "tagStr", "=", "new", "String", "(", "tag", ",", "\"ISO-8859-1\"", ")", ";", "return", "tagStr", ";", "}" ]
Read Dir Tab, return tag name @param in The stream to read from @return The string read @throws IOException Indicates a failure to read from the stream
[ "Read", "Dir", "Tab", "return", "tag", "name" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-hiero/src/main/java/org/newdawn/slick/tools/hiero/truetype/TTFDirTabEntry.java#L46-L59
1,763
nguillaumin/slick2d-maven
slick2d-peditor/src/main/java/org/newdawn/slick/tools/peditor/WhiskasPanel.java
WhiskasPanel.addEnableControl
private void addEnableControl(String text, ItemListener listener) { JCheckBox enableControl = new JCheckBox("Enable " + text); enableControl.setBounds(10, offset, 200, 20); enableControl.addItemListener(listener); add(enableControl); controlToValueName.put(enableControl, text); valueNameToControl.put(text, enableControl); offset += 25; }
java
private void addEnableControl(String text, ItemListener listener) { JCheckBox enableControl = new JCheckBox("Enable " + text); enableControl.setBounds(10, offset, 200, 20); enableControl.addItemListener(listener); add(enableControl); controlToValueName.put(enableControl, text); valueNameToControl.put(text, enableControl); offset += 25; }
[ "private", "void", "addEnableControl", "(", "String", "text", ",", "ItemListener", "listener", ")", "{", "JCheckBox", "enableControl", "=", "new", "JCheckBox", "(", "\"Enable \"", "+", "text", ")", ";", "enableControl", ".", "setBounds", "(", "10", ",", "offset", ",", "200", ",", "20", ")", ";", "enableControl", ".", "addItemListener", "(", "listener", ")", ";", "add", "(", "enableControl", ")", ";", "controlToValueName", ".", "put", "(", "enableControl", ",", "text", ")", ";", "valueNameToControl", ".", "put", "(", "text", ",", "enableControl", ")", ";", "offset", "+=", "25", ";", "}" ]
Add a control for enablement @param text The label to be associated with the check box @param listener The listener to be notified of updates to the new control
[ "Add", "a", "control", "for", "enablement" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-peditor/src/main/java/org/newdawn/slick/tools/peditor/WhiskasPanel.java#L79-L88
1,764
nguillaumin/slick2d-maven
slick2d-peditor/src/main/java/org/newdawn/slick/tools/peditor/WhiskasPanel.java
WhiskasPanel.itemStateChangedHandler
public void itemStateChangedHandler(ItemEvent e) { String valueName = (String) controlToValueName.get(e.getSource()); LinearInterpolator value = (LinearInterpolator) valueMap.get(valueName); if (e.getStateChange() == ItemEvent.SELECTED) { value.setActive(true); editor.registerValue(value, valueName); } else { value.setActive(false); editor.removeValue(valueName); } }
java
public void itemStateChangedHandler(ItemEvent e) { String valueName = (String) controlToValueName.get(e.getSource()); LinearInterpolator value = (LinearInterpolator) valueMap.get(valueName); if (e.getStateChange() == ItemEvent.SELECTED) { value.setActive(true); editor.registerValue(value, valueName); } else { value.setActive(false); editor.removeValue(valueName); } }
[ "public", "void", "itemStateChangedHandler", "(", "ItemEvent", "e", ")", "{", "String", "valueName", "=", "(", "String", ")", "controlToValueName", ".", "get", "(", "e", ".", "getSource", "(", ")", ")", ";", "LinearInterpolator", "value", "=", "(", "LinearInterpolator", ")", "valueMap", ".", "get", "(", "valueName", ")", ";", "if", "(", "e", ".", "getStateChange", "(", ")", "==", "ItemEvent", ".", "SELECTED", ")", "{", "value", ".", "setActive", "(", "true", ")", ";", "editor", ".", "registerValue", "(", "value", ",", "valueName", ")", ";", "}", "else", "{", "value", ".", "setActive", "(", "false", ")", ";", "editor", ".", "removeValue", "(", "valueName", ")", ";", "}", "}" ]
Notificaiton that one of the configuration option has changed state @param e The event describing the change of state
[ "Notificaiton", "that", "one", "of", "the", "configuration", "option", "has", "changed", "state" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-peditor/src/main/java/org/newdawn/slick/tools/peditor/WhiskasPanel.java#L95-L106
1,765
nguillaumin/slick2d-maven
slick2d-peditor/src/main/java/org/newdawn/slick/tools/peditor/WhiskasPanel.java
WhiskasPanel.linkToEmitter
private void linkToEmitter(String name, LinearInterpolator interpol) { // put to value map valueMap.put(name, interpol); // now update the checkbox to represent the state of the given // interpolator boolean checked = interpol.isActive(); JCheckBox enableControl = (JCheckBox) valueNameToControl.get(name); enableControl.setSelected(false); if (checked) enableControl.setSelected(checked); }
java
private void linkToEmitter(String name, LinearInterpolator interpol) { // put to value map valueMap.put(name, interpol); // now update the checkbox to represent the state of the given // interpolator boolean checked = interpol.isActive(); JCheckBox enableControl = (JCheckBox) valueNameToControl.get(name); enableControl.setSelected(false); if (checked) enableControl.setSelected(checked); }
[ "private", "void", "linkToEmitter", "(", "String", "name", ",", "LinearInterpolator", "interpol", ")", "{", "// put to value map\r", "valueMap", ".", "put", "(", "name", ",", "interpol", ")", ";", "// now update the checkbox to represent the state of the given\r", "// interpolator\r", "boolean", "checked", "=", "interpol", ".", "isActive", "(", ")", ";", "JCheckBox", "enableControl", "=", "(", "JCheckBox", ")", "valueNameToControl", ".", "get", "(", "name", ")", ";", "enableControl", ".", "setSelected", "(", "false", ")", ";", "if", "(", "checked", ")", "enableControl", ".", "setSelected", "(", "checked", ")", ";", "}" ]
Link this set of controls to a linear interpolater within the particle emitter @param name The name of the article emitter being linked @param interpol The interpolator being configured
[ "Link", "this", "set", "of", "controls", "to", "a", "linear", "interpolater", "within", "the", "particle", "emitter" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-peditor/src/main/java/org/newdawn/slick/tools/peditor/WhiskasPanel.java#L141-L152
1,766
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/font/effects/ShadowEffect.java
ShadowEffect.blur
private void blur(BufferedImage image) { float[] matrix = GAUSSIAN_BLUR_KERNELS[blurKernelSize - 1]; Kernel gaussianBlur1 = new Kernel(matrix.length, 1, matrix); Kernel gaussianBlur2 = new Kernel(1, matrix.length, matrix); RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); ConvolveOp gaussianOp1 = new ConvolveOp(gaussianBlur1, ConvolveOp.EDGE_NO_OP, hints); ConvolveOp gaussianOp2 = new ConvolveOp(gaussianBlur2, ConvolveOp.EDGE_NO_OP, hints); BufferedImage scratchImage = EffectUtil.getScratchImage(); for (int i = 0; i < blurPasses; i++) { gaussianOp1.filter(image, scratchImage); gaussianOp2.filter(scratchImage, image); } }
java
private void blur(BufferedImage image) { float[] matrix = GAUSSIAN_BLUR_KERNELS[blurKernelSize - 1]; Kernel gaussianBlur1 = new Kernel(matrix.length, 1, matrix); Kernel gaussianBlur2 = new Kernel(1, matrix.length, matrix); RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); ConvolveOp gaussianOp1 = new ConvolveOp(gaussianBlur1, ConvolveOp.EDGE_NO_OP, hints); ConvolveOp gaussianOp2 = new ConvolveOp(gaussianBlur2, ConvolveOp.EDGE_NO_OP, hints); BufferedImage scratchImage = EffectUtil.getScratchImage(); for (int i = 0; i < blurPasses; i++) { gaussianOp1.filter(image, scratchImage); gaussianOp2.filter(scratchImage, image); } }
[ "private", "void", "blur", "(", "BufferedImage", "image", ")", "{", "float", "[", "]", "matrix", "=", "GAUSSIAN_BLUR_KERNELS", "[", "blurKernelSize", "-", "1", "]", ";", "Kernel", "gaussianBlur1", "=", "new", "Kernel", "(", "matrix", ".", "length", ",", "1", ",", "matrix", ")", ";", "Kernel", "gaussianBlur2", "=", "new", "Kernel", "(", "1", ",", "matrix", ".", "length", ",", "matrix", ")", ";", "RenderingHints", "hints", "=", "new", "RenderingHints", "(", "RenderingHints", ".", "KEY_RENDERING", ",", "RenderingHints", ".", "VALUE_RENDER_SPEED", ")", ";", "ConvolveOp", "gaussianOp1", "=", "new", "ConvolveOp", "(", "gaussianBlur1", ",", "ConvolveOp", ".", "EDGE_NO_OP", ",", "hints", ")", ";", "ConvolveOp", "gaussianOp2", "=", "new", "ConvolveOp", "(", "gaussianBlur2", ",", "ConvolveOp", ".", "EDGE_NO_OP", ",", "hints", ")", ";", "BufferedImage", "scratchImage", "=", "EffectUtil", ".", "getScratchImage", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "blurPasses", ";", "i", "++", ")", "{", "gaussianOp1", ".", "filter", "(", "image", ",", "scratchImage", ")", ";", "gaussianOp2", ".", "filter", "(", "scratchImage", ",", "image", ")", ";", "}", "}" ]
Apply blurring to the generate image @param image The image to be blurred
[ "Apply", "blurring", "to", "the", "generate", "image" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/font/effects/ShadowEffect.java#L97-L109
1,767
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/opengl/InternalTextureLoader.java
InternalTextureLoader.getTexture
public Texture getTexture(File source, boolean flipped,int filter) throws IOException { String resourceName = source.getAbsolutePath(); InputStream in = new FileInputStream(source); return getTexture(in, resourceName, flipped, filter, null); }
java
public Texture getTexture(File source, boolean flipped,int filter) throws IOException { String resourceName = source.getAbsolutePath(); InputStream in = new FileInputStream(source); return getTexture(in, resourceName, flipped, filter, null); }
[ "public", "Texture", "getTexture", "(", "File", "source", ",", "boolean", "flipped", ",", "int", "filter", ")", "throws", "IOException", "{", "String", "resourceName", "=", "source", ".", "getAbsolutePath", "(", ")", ";", "InputStream", "in", "=", "new", "FileInputStream", "(", "source", ")", ";", "return", "getTexture", "(", "in", ",", "resourceName", ",", "flipped", ",", "filter", ",", "null", ")", ";", "}" ]
Get a texture from a specific file @param source The file to load the texture from @param flipped True if we should flip the texture on the y axis while loading @param filter The filter to use @return The texture loaded @throws IOException Indicates a failure to load the image
[ "Get", "a", "texture", "from", "a", "specific", "file" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/opengl/InternalTextureLoader.java#L135-L140
1,768
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/opengl/InternalTextureLoader.java
InternalTextureLoader.getTexture
public Texture getTexture(String resourceName, boolean flipped, int filter) throws IOException { InputStream in = ResourceLoader.getResourceAsStream(resourceName); return getTexture(in, resourceName, flipped, filter, null); }
java
public Texture getTexture(String resourceName, boolean flipped, int filter) throws IOException { InputStream in = ResourceLoader.getResourceAsStream(resourceName); return getTexture(in, resourceName, flipped, filter, null); }
[ "public", "Texture", "getTexture", "(", "String", "resourceName", ",", "boolean", "flipped", ",", "int", "filter", ")", "throws", "IOException", "{", "InputStream", "in", "=", "ResourceLoader", ".", "getResourceAsStream", "(", "resourceName", ")", ";", "return", "getTexture", "(", "in", ",", "resourceName", ",", "flipped", ",", "filter", ",", "null", ")", ";", "}" ]
Get a texture from a resource location @param resourceName The location to load the texture from @param flipped True if we should flip the texture on the y axis while loading @param filter The filter to use when scaling the texture @return The texture loaded @throws IOException Indicates a failure to load the image
[ "Get", "a", "texture", "from", "a", "resource", "location" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/opengl/InternalTextureLoader.java#L168-L172
1,769
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/opengl/InternalTextureLoader.java
InternalTextureLoader.reload
public void reload() { Iterator texs = texturesLinear.values().iterator(); while (texs.hasNext()) { ((TextureImpl) texs.next()).reload(); } texs = texturesNearest.values().iterator(); while (texs.hasNext()) { ((TextureImpl) texs.next()).reload(); } }
java
public void reload() { Iterator texs = texturesLinear.values().iterator(); while (texs.hasNext()) { ((TextureImpl) texs.next()).reload(); } texs = texturesNearest.values().iterator(); while (texs.hasNext()) { ((TextureImpl) texs.next()).reload(); } }
[ "public", "void", "reload", "(", ")", "{", "Iterator", "texs", "=", "texturesLinear", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "texs", ".", "hasNext", "(", ")", ")", "{", "(", "(", "TextureImpl", ")", "texs", ".", "next", "(", ")", ")", ".", "reload", "(", ")", ";", "}", "texs", "=", "texturesNearest", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "texs", ".", "hasNext", "(", ")", ")", "{", "(", "(", "TextureImpl", ")", "texs", ".", "next", "(", ")", ")", ".", "reload", "(", ")", ";", "}", "}" ]
Reload all the textures loaded in this loader
[ "Reload", "all", "the", "textures", "loaded", "in", "this", "loader" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/opengl/InternalTextureLoader.java#L486-L495
1,770
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/opengl/InternalTextureLoader.java
InternalTextureLoader.reload
public int reload(TextureImpl texture, int srcPixelFormat, int componentCount, int minFilter, int magFilter, ByteBuffer textureBuffer) { int target = SGL.GL_TEXTURE_2D; int textureID = createTextureID(); GL.glBindTexture(target, textureID); GL.glTexParameteri(target, SGL.GL_TEXTURE_MIN_FILTER, minFilter); GL.glTexParameteri(target, SGL.GL_TEXTURE_MAG_FILTER, magFilter); // produce a texture from the byte buffer GL.glTexImage2D(target, 0, dstPixelFormat, texture.getTextureWidth(), texture.getTextureHeight(), 0, srcPixelFormat, SGL.GL_UNSIGNED_BYTE, textureBuffer); return textureID; }
java
public int reload(TextureImpl texture, int srcPixelFormat, int componentCount, int minFilter, int magFilter, ByteBuffer textureBuffer) { int target = SGL.GL_TEXTURE_2D; int textureID = createTextureID(); GL.glBindTexture(target, textureID); GL.glTexParameteri(target, SGL.GL_TEXTURE_MIN_FILTER, minFilter); GL.glTexParameteri(target, SGL.GL_TEXTURE_MAG_FILTER, magFilter); // produce a texture from the byte buffer GL.glTexImage2D(target, 0, dstPixelFormat, texture.getTextureWidth(), texture.getTextureHeight(), 0, srcPixelFormat, SGL.GL_UNSIGNED_BYTE, textureBuffer); return textureID; }
[ "public", "int", "reload", "(", "TextureImpl", "texture", ",", "int", "srcPixelFormat", ",", "int", "componentCount", ",", "int", "minFilter", ",", "int", "magFilter", ",", "ByteBuffer", "textureBuffer", ")", "{", "int", "target", "=", "SGL", ".", "GL_TEXTURE_2D", ";", "int", "textureID", "=", "createTextureID", "(", ")", ";", "GL", ".", "glBindTexture", "(", "target", ",", "textureID", ")", ";", "GL", ".", "glTexParameteri", "(", "target", ",", "SGL", ".", "GL_TEXTURE_MIN_FILTER", ",", "minFilter", ")", ";", "GL", ".", "glTexParameteri", "(", "target", ",", "SGL", ".", "GL_TEXTURE_MAG_FILTER", ",", "magFilter", ")", ";", "// produce a texture from the byte buffer\r", "GL", ".", "glTexImage2D", "(", "target", ",", "0", ",", "dstPixelFormat", ",", "texture", ".", "getTextureWidth", "(", ")", ",", "texture", ".", "getTextureHeight", "(", ")", ",", "0", ",", "srcPixelFormat", ",", "SGL", ".", "GL_UNSIGNED_BYTE", ",", "textureBuffer", ")", ";", "return", "textureID", ";", "}" ]
Reload a given texture blob @param texture The texture being reloaded @param srcPixelFormat The source pixel format @param componentCount The component count @param minFilter The minification filter @param magFilter The magnification filter @param textureBuffer The pixel data @return The ID of the newly created texture
[ "Reload", "a", "given", "texture", "blob" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/opengl/InternalTextureLoader.java#L508-L529
1,771
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/PackedSpriteSheet.java
PackedSpriteSheet.getSprite
public Image getSprite(String name) { Section section = (Section) sections.get(name); if (section == null) { throw new RuntimeException("Unknown sprite from packed sheet: "+name); } return image.getSubImage(section.x, section.y, section.width, section.height); }
java
public Image getSprite(String name) { Section section = (Section) sections.get(name); if (section == null) { throw new RuntimeException("Unknown sprite from packed sheet: "+name); } return image.getSubImage(section.x, section.y, section.width, section.height); }
[ "public", "Image", "getSprite", "(", "String", "name", ")", "{", "Section", "section", "=", "(", "Section", ")", "sections", ".", "get", "(", "name", ")", ";", "if", "(", "section", "==", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"Unknown sprite from packed sheet: \"", "+", "name", ")", ";", "}", "return", "image", ".", "getSubImage", "(", "section", ".", "x", ",", "section", ".", "y", ",", "section", ".", "width", ",", "section", ".", "height", ")", ";", "}" ]
Get a single named sprite from the sheet @param name The name of the sprite to retrieve @return The sprite requested (image of)
[ "Get", "a", "single", "named", "sprite", "from", "the", "sheet" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/PackedSpriteSheet.java#L96-L104
1,772
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/PackedSpriteSheet.java
PackedSpriteSheet.getSpriteSheet
public SpriteSheet getSpriteSheet(String name) { Image image = getSprite(name); Section section = (Section) sections.get(name); return new SpriteSheet(image, section.width / section.tilesx, section.height / section.tilesy); }
java
public SpriteSheet getSpriteSheet(String name) { Image image = getSprite(name); Section section = (Section) sections.get(name); return new SpriteSheet(image, section.width / section.tilesx, section.height / section.tilesy); }
[ "public", "SpriteSheet", "getSpriteSheet", "(", "String", "name", ")", "{", "Image", "image", "=", "getSprite", "(", "name", ")", ";", "Section", "section", "=", "(", "Section", ")", "sections", ".", "get", "(", "name", ")", ";", "return", "new", "SpriteSheet", "(", "image", ",", "section", ".", "width", "/", "section", ".", "tilesx", ",", "section", ".", "height", "/", "section", ".", "tilesy", ")", ";", "}" ]
Get a sprite sheet that has been packed into the greater image @param name The name of the sprite sheet to retrieve @return The sprite sheet from the packed sheet
[ "Get", "a", "sprite", "sheet", "that", "has", "been", "packed", "into", "the", "greater", "image" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/PackedSpriteSheet.java#L112-L117
1,773
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/PackedSpriteSheet.java
PackedSpriteSheet.loadDefinition
private void loadDefinition(String def, Color trans) throws SlickException { BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def))); try { image = new Image(basePath+reader.readLine(), false, filter, trans); while (reader.ready()) { if (reader.readLine() == null) { break; } Section sect = new Section(reader); sections.put(sect.name, sect); if (reader.readLine() == null) { break; } } } catch (Exception e) { Log.error(e); throw new SlickException("Failed to process definitions file - invalid format?", e); } }
java
private void loadDefinition(String def, Color trans) throws SlickException { BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def))); try { image = new Image(basePath+reader.readLine(), false, filter, trans); while (reader.ready()) { if (reader.readLine() == null) { break; } Section sect = new Section(reader); sections.put(sect.name, sect); if (reader.readLine() == null) { break; } } } catch (Exception e) { Log.error(e); throw new SlickException("Failed to process definitions file - invalid format?", e); } }
[ "private", "void", "loadDefinition", "(", "String", "def", ",", "Color", "trans", ")", "throws", "SlickException", "{", "BufferedReader", "reader", "=", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "ResourceLoader", ".", "getResourceAsStream", "(", "def", ")", ")", ")", ";", "try", "{", "image", "=", "new", "Image", "(", "basePath", "+", "reader", ".", "readLine", "(", ")", ",", "false", ",", "filter", ",", "trans", ")", ";", "while", "(", "reader", ".", "ready", "(", ")", ")", "{", "if", "(", "reader", ".", "readLine", "(", ")", "==", "null", ")", "{", "break", ";", "}", "Section", "sect", "=", "new", "Section", "(", "reader", ")", ";", "sections", ".", "put", "(", "sect", ".", "name", ",", "sect", ")", ";", "if", "(", "reader", ".", "readLine", "(", ")", "==", "null", ")", "{", "break", ";", "}", "}", "}", "catch", "(", "Exception", "e", ")", "{", "Log", ".", "error", "(", "e", ")", ";", "throw", "new", "SlickException", "(", "\"Failed to process definitions file - invalid format?\"", ",", "e", ")", ";", "}", "}" ]
Load the definition file and parse each of the sections @param def The location of the definitions file @param trans The color to be treated as transparent @throws SlickException Indicates a failure to read or parse the definitions file or referenced image.
[ "Load", "the", "definition", "file", "and", "parse", "each", "of", "the", "sections" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/PackedSpriteSheet.java#L127-L148
1,774
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/geom/MannTriangulator.java
MannTriangulator.reset
public void reset() { while (holes != null) { holes = freePointBag(holes); } contour.clear(); holes = null; }
java
public void reset() { while (holes != null) { holes = freePointBag(holes); } contour.clear(); holes = null; }
[ "public", "void", "reset", "(", ")", "{", "while", "(", "holes", "!=", "null", ")", "{", "holes", "=", "freePointBag", "(", "holes", ")", ";", "}", "contour", ".", "clear", "(", ")", ";", "holes", "=", "null", ";", "}" ]
Reset the internal state of the triangulator
[ "Reset", "the", "internal", "state", "of", "the", "triangulator" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/geom/MannTriangulator.java#L69-L76
1,775
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/geom/MannTriangulator.java
MannTriangulator.addPoint
private void addPoint(Vector2f pt) { if (holes == null) { Point p = getPoint(pt); contour.add(p); } else { Point p = getPoint(pt); holes.add(p); } }
java
private void addPoint(Vector2f pt) { if (holes == null) { Point p = getPoint(pt); contour.add(p); } else { Point p = getPoint(pt); holes.add(p); } }
[ "private", "void", "addPoint", "(", "Vector2f", "pt", ")", "{", "if", "(", "holes", "==", "null", ")", "{", "Point", "p", "=", "getPoint", "(", "pt", ")", ";", "contour", ".", "add", "(", "p", ")", ";", "}", "else", "{", "Point", "p", "=", "getPoint", "(", "pt", ")", ";", "holes", ".", "add", "(", "p", ")", ";", "}", "}" ]
Add a defined point to the current contour @param pt The point to add
[ "Add", "a", "defined", "point", "to", "the", "current", "contour" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/geom/MannTriangulator.java#L92-L100
1,776
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/geom/MannTriangulator.java
MannTriangulator.freePointBag
private PointBag freePointBag(PointBag pb) { PointBag next = pb.next; pb.clear(); pb.next = nextFreePointBag; nextFreePointBag = pb; return next; }
java
private PointBag freePointBag(PointBag pb) { PointBag next = pb.next; pb.clear(); pb.next = nextFreePointBag; nextFreePointBag = pb; return next; }
[ "private", "PointBag", "freePointBag", "(", "PointBag", "pb", ")", "{", "PointBag", "next", "=", "pb", ".", "next", ";", "pb", ".", "clear", "(", ")", ";", "pb", ".", "next", "=", "nextFreePointBag", ";", "nextFreePointBag", "=", "pb", ";", "return", "next", ";", "}" ]
Release a pooled bag @param pb The bag to release @return The next available bag
[ "Release", "a", "pooled", "bag" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/geom/MannTriangulator.java#L244-L250
1,777
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/geom/MannTriangulator.java
MannTriangulator.getPoint
private Point getPoint(Vector2f pt) { Point p = nextFreePoint; if (p != null) { nextFreePoint = p.next; // initialize new point to safe values p.next = null; p.prev = null; p.pt = pt; return p; } return new Point(pt); }
java
private Point getPoint(Vector2f pt) { Point p = nextFreePoint; if (p != null) { nextFreePoint = p.next; // initialize new point to safe values p.next = null; p.prev = null; p.pt = pt; return p; } return new Point(pt); }
[ "private", "Point", "getPoint", "(", "Vector2f", "pt", ")", "{", "Point", "p", "=", "nextFreePoint", ";", "if", "(", "p", "!=", "null", ")", "{", "nextFreePoint", "=", "p", ".", "next", ";", "// initialize new point to safe values\r", "p", ".", "next", "=", "null", ";", "p", ".", "prev", "=", "null", ";", "p", ".", "pt", "=", "pt", ";", "return", "p", ";", "}", "return", "new", "Point", "(", "pt", ")", ";", "}" ]
Create or reuse a point @param pt The point data to set @return The new point
[ "Create", "or", "reuse", "a", "point" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/geom/MannTriangulator.java#L258-L269
1,778
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/geom/MannTriangulator.java
MannTriangulator.freePoints
private void freePoints(Point head) { head.prev.next = nextFreePoint; head.prev = null; nextFreePoint = head; }
java
private void freePoints(Point head) { head.prev.next = nextFreePoint; head.prev = null; nextFreePoint = head; }
[ "private", "void", "freePoints", "(", "Point", "head", ")", "{", "head", ".", "prev", ".", "next", "=", "nextFreePoint", ";", "head", ".", "prev", "=", "null", ";", "nextFreePoint", "=", "head", ";", "}" ]
Release all points @param head The head of the points bag
[ "Release", "all", "points" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/geom/MannTriangulator.java#L286-L290
1,779
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/openal/OpenALStreamPlayer.java
OpenALStreamPlayer.initStreams
private void initStreams() throws IOException { if (audio != null) { audio.close(); } OggInputStream audio; if (url != null) { audio = new OggInputStream(url.openStream()); } else { audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref)); } this.audio = audio; positionOffset = 0; }
java
private void initStreams() throws IOException { if (audio != null) { audio.close(); } OggInputStream audio; if (url != null) { audio = new OggInputStream(url.openStream()); } else { audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref)); } this.audio = audio; positionOffset = 0; }
[ "private", "void", "initStreams", "(", ")", "throws", "IOException", "{", "if", "(", "audio", "!=", "null", ")", "{", "audio", ".", "close", "(", ")", ";", "}", "OggInputStream", "audio", ";", "if", "(", "url", "!=", "null", ")", "{", "audio", "=", "new", "OggInputStream", "(", "url", ".", "openStream", "(", ")", ")", ";", "}", "else", "{", "audio", "=", "new", "OggInputStream", "(", "ResourceLoader", ".", "getResourceAsStream", "(", "ref", ")", ")", ";", "}", "this", ".", "audio", "=", "audio", ";", "positionOffset", "=", "0", ";", "}" ]
Initialise our connection to the underlying resource @throws IOException Indicates a failure to open the underling resource
[ "Initialise", "our", "connection", "to", "the", "underlying", "resource" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/openal/OpenALStreamPlayer.java#L89-L104
1,780
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/openal/OpenALStreamPlayer.java
OpenALStreamPlayer.play
public void play(boolean loop) throws IOException { this.loop = loop; initStreams(); done = false; AL10.alSourceStop(source); removeBuffers(); startPlayback(); }
java
public void play(boolean loop) throws IOException { this.loop = loop; initStreams(); done = false; AL10.alSourceStop(source); removeBuffers(); startPlayback(); }
[ "public", "void", "play", "(", "boolean", "loop", ")", "throws", "IOException", "{", "this", ".", "loop", "=", "loop", ";", "initStreams", "(", ")", ";", "done", "=", "false", ";", "AL10", ".", "alSourceStop", "(", "source", ")", ";", "removeBuffers", "(", ")", ";", "startPlayback", "(", ")", ";", "}" ]
Start this stream playing @param loop True if the stream should loop @throws IOException Indicates a failure to read from the stream
[ "Start", "this", "stream", "playing" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/openal/OpenALStreamPlayer.java#L135-L145
1,781
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/openal/OpenALStreamPlayer.java
OpenALStreamPlayer.stream
public boolean stream(int bufferId) { try { int count = audio.read(buffer); if (count != -1) { bufferData.clear(); bufferData.put(buffer,0,count); bufferData.flip(); int format = audio.getChannels() > 1 ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_MONO16; try { AL10.alBufferData(bufferId, format, bufferData, audio.getRate()); } catch (OpenALException e) { Log.error("Failed to loop buffer: "+bufferId+" "+format+" "+count+" "+audio.getRate(), e); return false; } } else { if (loop) { initStreams(); stream(bufferId); } else { done = true; return false; } } return true; } catch (IOException e) { Log.error(e); return false; } }
java
public boolean stream(int bufferId) { try { int count = audio.read(buffer); if (count != -1) { bufferData.clear(); bufferData.put(buffer,0,count); bufferData.flip(); int format = audio.getChannels() > 1 ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_MONO16; try { AL10.alBufferData(bufferId, format, bufferData, audio.getRate()); } catch (OpenALException e) { Log.error("Failed to loop buffer: "+bufferId+" "+format+" "+count+" "+audio.getRate(), e); return false; } } else { if (loop) { initStreams(); stream(bufferId); } else { done = true; return false; } } return true; } catch (IOException e) { Log.error(e); return false; } }
[ "public", "boolean", "stream", "(", "int", "bufferId", ")", "{", "try", "{", "int", "count", "=", "audio", ".", "read", "(", "buffer", ")", ";", "if", "(", "count", "!=", "-", "1", ")", "{", "bufferData", ".", "clear", "(", ")", ";", "bufferData", ".", "put", "(", "buffer", ",", "0", ",", "count", ")", ";", "bufferData", ".", "flip", "(", ")", ";", "int", "format", "=", "audio", ".", "getChannels", "(", ")", ">", "1", "?", "AL10", ".", "AL_FORMAT_STEREO16", ":", "AL10", ".", "AL_FORMAT_MONO16", ";", "try", "{", "AL10", ".", "alBufferData", "(", "bufferId", ",", "format", ",", "bufferData", ",", "audio", ".", "getRate", "(", ")", ")", ";", "}", "catch", "(", "OpenALException", "e", ")", "{", "Log", ".", "error", "(", "\"Failed to loop buffer: \"", "+", "bufferId", "+", "\" \"", "+", "format", "+", "\" \"", "+", "count", "+", "\" \"", "+", "audio", ".", "getRate", "(", ")", ",", "e", ")", ";", "return", "false", ";", "}", "}", "else", "{", "if", "(", "loop", ")", "{", "initStreams", "(", ")", ";", "stream", "(", "bufferId", ")", ";", "}", "else", "{", "done", "=", "true", ";", "return", "false", ";", "}", "}", "return", "true", ";", "}", "catch", "(", "IOException", "e", ")", "{", "Log", ".", "error", "(", "e", ")", ";", "return", "false", ";", "}", "}" ]
Stream some data from the audio stream to the buffer indicates by the ID @param bufferId The ID of the buffer to fill @return True if another section was available
[ "Stream", "some", "data", "from", "the", "audio", "stream", "to", "the", "buffer", "indicates", "by", "the", "ID" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/openal/OpenALStreamPlayer.java#L219-L250
1,782
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/openal/OpenALStreamPlayer.java
OpenALStreamPlayer.setPosition
public boolean setPosition(float position) { try { if (getPosition() > position) { initStreams(); } float sampleRate = audio.getRate(); float sampleSize; if (audio.getChannels() > 1) { sampleSize = 4; // AL10.AL_FORMAT_STEREO16 } else { sampleSize = 2; // AL10.AL_FORMAT_MONO16 } while (positionOffset < position) { int count = audio.read(buffer); if (count != -1) { float bufferLength = (count / sampleSize) / sampleRate; positionOffset += bufferLength; } else { if (loop) { initStreams(); } else { done = true; } return false; } } startPlayback(); return true; } catch (IOException e) { Log.error(e); return false; } }
java
public boolean setPosition(float position) { try { if (getPosition() > position) { initStreams(); } float sampleRate = audio.getRate(); float sampleSize; if (audio.getChannels() > 1) { sampleSize = 4; // AL10.AL_FORMAT_STEREO16 } else { sampleSize = 2; // AL10.AL_FORMAT_MONO16 } while (positionOffset < position) { int count = audio.read(buffer); if (count != -1) { float bufferLength = (count / sampleSize) / sampleRate; positionOffset += bufferLength; } else { if (loop) { initStreams(); } else { done = true; } return false; } } startPlayback(); return true; } catch (IOException e) { Log.error(e); return false; } }
[ "public", "boolean", "setPosition", "(", "float", "position", ")", "{", "try", "{", "if", "(", "getPosition", "(", ")", ">", "position", ")", "{", "initStreams", "(", ")", ";", "}", "float", "sampleRate", "=", "audio", ".", "getRate", "(", ")", ";", "float", "sampleSize", ";", "if", "(", "audio", ".", "getChannels", "(", ")", ">", "1", ")", "{", "sampleSize", "=", "4", ";", "// AL10.AL_FORMAT_STEREO16\r", "}", "else", "{", "sampleSize", "=", "2", ";", "// AL10.AL_FORMAT_MONO16\r", "}", "while", "(", "positionOffset", "<", "position", ")", "{", "int", "count", "=", "audio", ".", "read", "(", "buffer", ")", ";", "if", "(", "count", "!=", "-", "1", ")", "{", "float", "bufferLength", "=", "(", "count", "/", "sampleSize", ")", "/", "sampleRate", ";", "positionOffset", "+=", "bufferLength", ";", "}", "else", "{", "if", "(", "loop", ")", "{", "initStreams", "(", ")", ";", "}", "else", "{", "done", "=", "true", ";", "}", "return", "false", ";", "}", "}", "startPlayback", "(", ")", ";", "return", "true", ";", "}", "catch", "(", "IOException", "e", ")", "{", "Log", ".", "error", "(", "e", ")", ";", "return", "false", ";", "}", "}" ]
Seeks to a position in the music. @param position Position in seconds. @return True if the setting of the position was successful
[ "Seeks", "to", "a", "position", "in", "the", "music", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/openal/OpenALStreamPlayer.java#L258-L294
1,783
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/openal/OpenALStreamPlayer.java
OpenALStreamPlayer.startPlayback
private void startPlayback() { AL10.alSourcei(source, AL10.AL_LOOPING, AL10.AL_FALSE); AL10.alSourcef(source, AL10.AL_PITCH, pitch); remainingBufferCount = BUFFER_COUNT; for (int i = 0; i < BUFFER_COUNT; i++) { stream(bufferNames.get(i)); } AL10.alSourceQueueBuffers(source, bufferNames); AL10.alSourcePlay(source); }
java
private void startPlayback() { AL10.alSourcei(source, AL10.AL_LOOPING, AL10.AL_FALSE); AL10.alSourcef(source, AL10.AL_PITCH, pitch); remainingBufferCount = BUFFER_COUNT; for (int i = 0; i < BUFFER_COUNT; i++) { stream(bufferNames.get(i)); } AL10.alSourceQueueBuffers(source, bufferNames); AL10.alSourcePlay(source); }
[ "private", "void", "startPlayback", "(", ")", "{", "AL10", ".", "alSourcei", "(", "source", ",", "AL10", ".", "AL_LOOPING", ",", "AL10", ".", "AL_FALSE", ")", ";", "AL10", ".", "alSourcef", "(", "source", ",", "AL10", ".", "AL_PITCH", ",", "pitch", ")", ";", "remainingBufferCount", "=", "BUFFER_COUNT", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "BUFFER_COUNT", ";", "i", "++", ")", "{", "stream", "(", "bufferNames", ".", "get", "(", "i", ")", ")", ";", "}", "AL10", ".", "alSourceQueueBuffers", "(", "source", ",", "bufferNames", ")", ";", "AL10", ".", "alSourcePlay", "(", "source", ")", ";", "}" ]
Starts the streaming.
[ "Starts", "the", "streaming", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/openal/OpenALStreamPlayer.java#L299-L311
1,784
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.reset
public void reset() { Iterator pools = particlesByEmitter.values().iterator(); while (pools.hasNext()) { ParticlePool pool = (ParticlePool) pools.next(); pool.reset(this); } for (int i=0;i<emitters.size();i++) { ParticleEmitter emitter = (ParticleEmitter) emitters.get(i); emitter.resetState(); } }
java
public void reset() { Iterator pools = particlesByEmitter.values().iterator(); while (pools.hasNext()) { ParticlePool pool = (ParticlePool) pools.next(); pool.reset(this); } for (int i=0;i<emitters.size();i++) { ParticleEmitter emitter = (ParticleEmitter) emitters.get(i); emitter.resetState(); } }
[ "public", "void", "reset", "(", ")", "{", "Iterator", "pools", "=", "particlesByEmitter", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "pools", ".", "hasNext", "(", ")", ")", "{", "ParticlePool", "pool", "=", "(", "ParticlePool", ")", "pools", ".", "next", "(", ")", ";", "pool", ".", "reset", "(", "this", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "emitters", ".", "size", "(", ")", ";", "i", "++", ")", "{", "ParticleEmitter", "emitter", "=", "(", "ParticleEmitter", ")", "emitters", ".", "get", "(", "i", ")", ";", "emitter", ".", "resetState", "(", ")", ";", "}", "}" ]
Reset the state of the system
[ "Reset", "the", "state", "of", "the", "system" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L156-L167
1,785
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.addEmitter
public void addEmitter(ParticleEmitter emitter) { emitters.add(emitter); ParticlePool pool= new ParticlePool( this, maxParticlesPerEmitter ); particlesByEmitter.put( emitter, pool ); }
java
public void addEmitter(ParticleEmitter emitter) { emitters.add(emitter); ParticlePool pool= new ParticlePool( this, maxParticlesPerEmitter ); particlesByEmitter.put( emitter, pool ); }
[ "public", "void", "addEmitter", "(", "ParticleEmitter", "emitter", ")", "{", "emitters", ".", "add", "(", "emitter", ")", ";", "ParticlePool", "pool", "=", "new", "ParticlePool", "(", "this", ",", "maxParticlesPerEmitter", ")", ";", "particlesByEmitter", ".", "put", "(", "emitter", ",", "pool", ")", ";", "}" ]
Add a particle emitter to be used on this system @param emitter The emitter to be added
[ "Add", "a", "particle", "emitter", "to", "be", "used", "on", "this", "system" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L319-L324
1,786
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.removeAllEmitters
public void removeAllEmitters() { for (int i=0;i<emitters.size();i++) { removeEmitter((ParticleEmitter) emitters.get(i)); i--; } }
java
public void removeAllEmitters() { for (int i=0;i<emitters.size();i++) { removeEmitter((ParticleEmitter) emitters.get(i)); i--; } }
[ "public", "void", "removeAllEmitters", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "emitters", ".", "size", "(", ")", ";", "i", "++", ")", "{", "removeEmitter", "(", "(", "ParticleEmitter", ")", "emitters", ".", "get", "(", "i", ")", ")", ";", "i", "--", ";", "}", "}" ]
Remove all the emitters from the system
[ "Remove", "all", "the", "emitters", "from", "the", "system" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L339-L344
1,787
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.render
public void render(float x, float y) { if ((sprite == null) && (defaultImageName != null)) { loadSystemParticleImage(); } if (!visible) { return; } GL.glTranslatef(x,y,0); if (blendingMode == BLEND_ADDITIVE) { GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE); } if (usePoints()) { GL.glEnable( SGL.GL_POINT_SMOOTH ); TextureImpl.bindNone(); } // iterate over all emitters for( int emitterIdx=0; emitterIdx<emitters.size(); emitterIdx++ ) { // get emitter ParticleEmitter emitter = (ParticleEmitter) emitters.get(emitterIdx); if (!emitter.isEnabled()) { continue; } // check for additive override and enable when set if (emitter.useAdditive()) { GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE); } // now get the particle pool for this emitter and render all particles that are in use ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter); Image image = emitter.getImage(); if (image == null) { image = this.sprite; } if (!emitter.isOriented() && !emitter.usePoints(this)) { image.startUse(); } for (int i = 0; i < pool.particles.length; i++) { if (pool.particles[i].inUse()) pool.particles[i].render(); } if (!emitter.isOriented() && !emitter.usePoints(this)) { image.endUse(); } // reset additive blend mode if (emitter.useAdditive()) { GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE_MINUS_SRC_ALPHA); } } if (usePoints()) { GL.glDisable( SGL.GL_POINT_SMOOTH ); } if (blendingMode == BLEND_ADDITIVE) { GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE_MINUS_SRC_ALPHA); } Color.white.bind(); GL.glTranslatef(-x,-y,0); }
java
public void render(float x, float y) { if ((sprite == null) && (defaultImageName != null)) { loadSystemParticleImage(); } if (!visible) { return; } GL.glTranslatef(x,y,0); if (blendingMode == BLEND_ADDITIVE) { GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE); } if (usePoints()) { GL.glEnable( SGL.GL_POINT_SMOOTH ); TextureImpl.bindNone(); } // iterate over all emitters for( int emitterIdx=0; emitterIdx<emitters.size(); emitterIdx++ ) { // get emitter ParticleEmitter emitter = (ParticleEmitter) emitters.get(emitterIdx); if (!emitter.isEnabled()) { continue; } // check for additive override and enable when set if (emitter.useAdditive()) { GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE); } // now get the particle pool for this emitter and render all particles that are in use ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter); Image image = emitter.getImage(); if (image == null) { image = this.sprite; } if (!emitter.isOriented() && !emitter.usePoints(this)) { image.startUse(); } for (int i = 0; i < pool.particles.length; i++) { if (pool.particles[i].inUse()) pool.particles[i].render(); } if (!emitter.isOriented() && !emitter.usePoints(this)) { image.endUse(); } // reset additive blend mode if (emitter.useAdditive()) { GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE_MINUS_SRC_ALPHA); } } if (usePoints()) { GL.glDisable( SGL.GL_POINT_SMOOTH ); } if (blendingMode == BLEND_ADDITIVE) { GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE_MINUS_SRC_ALPHA); } Color.white.bind(); GL.glTranslatef(-x,-y,0); }
[ "public", "void", "render", "(", "float", "x", ",", "float", "y", ")", "{", "if", "(", "(", "sprite", "==", "null", ")", "&&", "(", "defaultImageName", "!=", "null", ")", ")", "{", "loadSystemParticleImage", "(", ")", ";", "}", "if", "(", "!", "visible", ")", "{", "return", ";", "}", "GL", ".", "glTranslatef", "(", "x", ",", "y", ",", "0", ")", ";", "if", "(", "blendingMode", "==", "BLEND_ADDITIVE", ")", "{", "GL", ".", "glBlendFunc", "(", "SGL", ".", "GL_SRC_ALPHA", ",", "SGL", ".", "GL_ONE", ")", ";", "}", "if", "(", "usePoints", "(", ")", ")", "{", "GL", ".", "glEnable", "(", "SGL", ".", "GL_POINT_SMOOTH", ")", ";", "TextureImpl", ".", "bindNone", "(", ")", ";", "}", "// iterate over all emitters\r", "for", "(", "int", "emitterIdx", "=", "0", ";", "emitterIdx", "<", "emitters", ".", "size", "(", ")", ";", "emitterIdx", "++", ")", "{", "// get emitter\r", "ParticleEmitter", "emitter", "=", "(", "ParticleEmitter", ")", "emitters", ".", "get", "(", "emitterIdx", ")", ";", "if", "(", "!", "emitter", ".", "isEnabled", "(", ")", ")", "{", "continue", ";", "}", "// check for additive override and enable when set\r", "if", "(", "emitter", ".", "useAdditive", "(", ")", ")", "{", "GL", ".", "glBlendFunc", "(", "SGL", ".", "GL_SRC_ALPHA", ",", "SGL", ".", "GL_ONE", ")", ";", "}", "// now get the particle pool for this emitter and render all particles that are in use\r", "ParticlePool", "pool", "=", "(", "ParticlePool", ")", "particlesByEmitter", ".", "get", "(", "emitter", ")", ";", "Image", "image", "=", "emitter", ".", "getImage", "(", ")", ";", "if", "(", "image", "==", "null", ")", "{", "image", "=", "this", ".", "sprite", ";", "}", "if", "(", "!", "emitter", ".", "isOriented", "(", ")", "&&", "!", "emitter", ".", "usePoints", "(", "this", ")", ")", "{", "image", ".", "startUse", "(", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pool", ".", "particles", ".", "length", ";", "i", "++", ")", "{", "if", "(", "pool", ".", "particles", "[", "i", "]", ".", "inUse", "(", ")", ")", "pool", ".", "particles", "[", "i", "]", ".", "render", "(", ")", ";", "}", "if", "(", "!", "emitter", ".", "isOriented", "(", ")", "&&", "!", "emitter", ".", "usePoints", "(", "this", ")", ")", "{", "image", ".", "endUse", "(", ")", ";", "}", "// reset additive blend mode\r", "if", "(", "emitter", ".", "useAdditive", "(", ")", ")", "{", "GL", ".", "glBlendFunc", "(", "SGL", ".", "GL_SRC_ALPHA", ",", "SGL", ".", "GL_ONE_MINUS_SRC_ALPHA", ")", ";", "}", "}", "if", "(", "usePoints", "(", ")", ")", "{", "GL", ".", "glDisable", "(", "SGL", ".", "GL_POINT_SMOOTH", ")", ";", "}", "if", "(", "blendingMode", "==", "BLEND_ADDITIVE", ")", "{", "GL", ".", "glBlendFunc", "(", "SGL", ".", "GL_SRC_ALPHA", ",", "SGL", ".", "GL_ONE_MINUS_SRC_ALPHA", ")", ";", "}", "Color", ".", "white", ".", "bind", "(", ")", ";", "GL", ".", "glTranslatef", "(", "-", "x", ",", "-", "y", ",", "0", ")", ";", "}" ]
Render the particles in the system @param x The x coordinate to render the particle system at (in the current coordinate space) @param y The y coordinate to render the particle system at (in the current coordiante space)
[ "Render", "the", "particles", "in", "the", "system" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L389-L459
1,788
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.loadSystemParticleImage
private void loadSystemParticleImage() { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { if (mask != null) { sprite = new Image(defaultImageName, mask); } else { sprite = new Image(defaultImageName); } } catch (SlickException e) { Log.error(e); defaultImageName = null; } return null; // nothing to return } }); }
java
private void loadSystemParticleImage() { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { if (mask != null) { sprite = new Image(defaultImageName, mask); } else { sprite = new Image(defaultImageName); } } catch (SlickException e) { Log.error(e); defaultImageName = null; } return null; // nothing to return } }); }
[ "private", "void", "loadSystemParticleImage", "(", ")", "{", "AccessController", ".", "doPrivileged", "(", "new", "PrivilegedAction", "(", ")", "{", "public", "Object", "run", "(", ")", "{", "try", "{", "if", "(", "mask", "!=", "null", ")", "{", "sprite", "=", "new", "Image", "(", "defaultImageName", ",", "mask", ")", ";", "}", "else", "{", "sprite", "=", "new", "Image", "(", "defaultImageName", ")", ";", "}", "}", "catch", "(", "SlickException", "e", ")", "{", "Log", ".", "error", "(", "e", ")", ";", "defaultImageName", "=", "null", ";", "}", "return", "null", ";", "// nothing to return\r", "}", "}", ")", ";", "}" ]
Load the system particle image as the extension permissions
[ "Load", "the", "system", "particle", "image", "as", "the", "extension", "permissions" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L464-L480
1,789
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.update
public void update(int delta) { if ((sprite == null) && (defaultImageName != null)) { loadSystemParticleImage(); } removeMe.clear(); ArrayList emitters = new ArrayList(this.emitters); for (int i=0;i<emitters.size();i++) { ParticleEmitter emitter = (ParticleEmitter) emitters.get(i); if (emitter.isEnabled()) { emitter.update(this, delta); if (removeCompletedEmitters) { if (emitter.completed()) { removeMe.add(emitter); particlesByEmitter.remove(emitter); } } } } this.emitters.removeAll(removeMe); pCount = 0; if (!particlesByEmitter.isEmpty()) { Iterator it= particlesByEmitter.keySet().iterator(); while (it.hasNext()) { ParticleEmitter emitter = (ParticleEmitter) it.next(); if (emitter.isEnabled()) { ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter); for (int i=0;i<pool.particles.length;i++) { if (pool.particles[i].life > 0) { pool.particles[i].update(delta); pCount++; } } } } } }
java
public void update(int delta) { if ((sprite == null) && (defaultImageName != null)) { loadSystemParticleImage(); } removeMe.clear(); ArrayList emitters = new ArrayList(this.emitters); for (int i=0;i<emitters.size();i++) { ParticleEmitter emitter = (ParticleEmitter) emitters.get(i); if (emitter.isEnabled()) { emitter.update(this, delta); if (removeCompletedEmitters) { if (emitter.completed()) { removeMe.add(emitter); particlesByEmitter.remove(emitter); } } } } this.emitters.removeAll(removeMe); pCount = 0; if (!particlesByEmitter.isEmpty()) { Iterator it= particlesByEmitter.keySet().iterator(); while (it.hasNext()) { ParticleEmitter emitter = (ParticleEmitter) it.next(); if (emitter.isEnabled()) { ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter); for (int i=0;i<pool.particles.length;i++) { if (pool.particles[i].life > 0) { pool.particles[i].update(delta); pCount++; } } } } } }
[ "public", "void", "update", "(", "int", "delta", ")", "{", "if", "(", "(", "sprite", "==", "null", ")", "&&", "(", "defaultImageName", "!=", "null", ")", ")", "{", "loadSystemParticleImage", "(", ")", ";", "}", "removeMe", ".", "clear", "(", ")", ";", "ArrayList", "emitters", "=", "new", "ArrayList", "(", "this", ".", "emitters", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "emitters", ".", "size", "(", ")", ";", "i", "++", ")", "{", "ParticleEmitter", "emitter", "=", "(", "ParticleEmitter", ")", "emitters", ".", "get", "(", "i", ")", ";", "if", "(", "emitter", ".", "isEnabled", "(", ")", ")", "{", "emitter", ".", "update", "(", "this", ",", "delta", ")", ";", "if", "(", "removeCompletedEmitters", ")", "{", "if", "(", "emitter", ".", "completed", "(", ")", ")", "{", "removeMe", ".", "add", "(", "emitter", ")", ";", "particlesByEmitter", ".", "remove", "(", "emitter", ")", ";", "}", "}", "}", "}", "this", ".", "emitters", ".", "removeAll", "(", "removeMe", ")", ";", "pCount", "=", "0", ";", "if", "(", "!", "particlesByEmitter", ".", "isEmpty", "(", ")", ")", "{", "Iterator", "it", "=", "particlesByEmitter", ".", "keySet", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "ParticleEmitter", "emitter", "=", "(", "ParticleEmitter", ")", "it", ".", "next", "(", ")", ";", "if", "(", "emitter", ".", "isEnabled", "(", ")", ")", "{", "ParticlePool", "pool", "=", "(", "ParticlePool", ")", "particlesByEmitter", ".", "get", "(", "emitter", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pool", ".", "particles", ".", "length", ";", "i", "++", ")", "{", "if", "(", "pool", ".", "particles", "[", "i", "]", ".", "life", ">", "0", ")", "{", "pool", ".", "particles", "[", "i", "]", ".", "update", "(", "delta", ")", ";", "pCount", "++", ";", "}", "}", "}", "}", "}", "}" ]
Update the system, request the assigned emitters update the particles @param delta The amount of time thats passed since last update in milliseconds
[ "Update", "the", "system", "request", "the", "assigned", "emitters", "update", "the", "particles" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L487-L527
1,790
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.getNewParticle
public Particle getNewParticle(ParticleEmitter emitter, float life) { ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter); ArrayList available = pool.available; if (available.size() > 0) { Particle p = (Particle) available.remove(available.size()-1); p.init(emitter, life); p.setImage(sprite); return p; } Log.warn("Ran out of particles (increase the limit)!"); return dummy; }
java
public Particle getNewParticle(ParticleEmitter emitter, float life) { ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter); ArrayList available = pool.available; if (available.size() > 0) { Particle p = (Particle) available.remove(available.size()-1); p.init(emitter, life); p.setImage(sprite); return p; } Log.warn("Ran out of particles (increase the limit)!"); return dummy; }
[ "public", "Particle", "getNewParticle", "(", "ParticleEmitter", "emitter", ",", "float", "life", ")", "{", "ParticlePool", "pool", "=", "(", "ParticlePool", ")", "particlesByEmitter", ".", "get", "(", "emitter", ")", ";", "ArrayList", "available", "=", "pool", ".", "available", ";", "if", "(", "available", ".", "size", "(", ")", ">", "0", ")", "{", "Particle", "p", "=", "(", "Particle", ")", "available", ".", "remove", "(", "available", ".", "size", "(", ")", "-", "1", ")", ";", "p", ".", "init", "(", "emitter", ",", "life", ")", ";", "p", ".", "setImage", "(", "sprite", ")", ";", "return", "p", ";", "}", "Log", ".", "warn", "(", "\"Ran out of particles (increase the limit)!\"", ")", ";", "return", "dummy", ";", "}" ]
Get a new particle from the system. This should be used by emitters to request particles @param emitter The emitter requesting the particle @param life The time the new particle should live for @return A particle from the system
[ "Get", "a", "new", "particle", "from", "the", "system", ".", "This", "should", "be", "used", "by", "emitters", "to", "request", "particles" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L546-L561
1,791
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.release
public void release(Particle particle) { if (particle != dummy) { ParticlePool pool = (ParticlePool)particlesByEmitter.get( particle.getEmitter() ); pool.available.add(particle); } }
java
public void release(Particle particle) { if (particle != dummy) { ParticlePool pool = (ParticlePool)particlesByEmitter.get( particle.getEmitter() ); pool.available.add(particle); } }
[ "public", "void", "release", "(", "Particle", "particle", ")", "{", "if", "(", "particle", "!=", "dummy", ")", "{", "ParticlePool", "pool", "=", "(", "ParticlePool", ")", "particlesByEmitter", ".", "get", "(", "particle", ".", "getEmitter", "(", ")", ")", ";", "pool", ".", "available", ".", "add", "(", "particle", ")", ";", "}", "}" ]
Release a particle back to the system once it has expired @param particle The particle to be released
[ "Release", "a", "particle", "back", "to", "the", "system", "once", "it", "has", "expired" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L568-L574
1,792
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.releaseAll
public void releaseAll(ParticleEmitter emitter) { if( !particlesByEmitter.isEmpty() ) { Iterator it= particlesByEmitter.values().iterator(); while( it.hasNext()) { ParticlePool pool= (ParticlePool)it.next(); for (int i=0;i<pool.particles.length;i++) { if (pool.particles[i].inUse()) { if (pool.particles[i].getEmitter() == emitter) { pool.particles[i].setLife(-1); release(pool.particles[i]); } } } } } }
java
public void releaseAll(ParticleEmitter emitter) { if( !particlesByEmitter.isEmpty() ) { Iterator it= particlesByEmitter.values().iterator(); while( it.hasNext()) { ParticlePool pool= (ParticlePool)it.next(); for (int i=0;i<pool.particles.length;i++) { if (pool.particles[i].inUse()) { if (pool.particles[i].getEmitter() == emitter) { pool.particles[i].setLife(-1); release(pool.particles[i]); } } } } } }
[ "public", "void", "releaseAll", "(", "ParticleEmitter", "emitter", ")", "{", "if", "(", "!", "particlesByEmitter", ".", "isEmpty", "(", ")", ")", "{", "Iterator", "it", "=", "particlesByEmitter", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "ParticlePool", "pool", "=", "(", "ParticlePool", ")", "it", ".", "next", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pool", ".", "particles", ".", "length", ";", "i", "++", ")", "{", "if", "(", "pool", ".", "particles", "[", "i", "]", ".", "inUse", "(", ")", ")", "{", "if", "(", "pool", ".", "particles", "[", "i", "]", ".", "getEmitter", "(", ")", "==", "emitter", ")", "{", "pool", ".", "particles", "[", "i", "]", ".", "setLife", "(", "-", "1", ")", ";", "release", "(", "pool", ".", "particles", "[", "i", "]", ")", ";", "}", "}", "}", "}", "}", "}" ]
Release all the particles owned by the specified emitter @param emitter The emitter owning the particles that should be released
[ "Release", "all", "the", "particles", "owned", "by", "the", "specified", "emitter" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L581-L598
1,793
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.moveAll
public void moveAll(ParticleEmitter emitter, float x, float y) { ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter); for (int i=0;i<pool.particles.length;i++) { if (pool.particles[i].inUse()) { pool.particles[i].move(x, y); } } }
java
public void moveAll(ParticleEmitter emitter, float x, float y) { ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter); for (int i=0;i<pool.particles.length;i++) { if (pool.particles[i].inUse()) { pool.particles[i].move(x, y); } } }
[ "public", "void", "moveAll", "(", "ParticleEmitter", "emitter", ",", "float", "x", ",", "float", "y", ")", "{", "ParticlePool", "pool", "=", "(", "ParticlePool", ")", "particlesByEmitter", ".", "get", "(", "emitter", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pool", ".", "particles", ".", "length", ";", "i", "++", ")", "{", "if", "(", "pool", ".", "particles", "[", "i", "]", ".", "inUse", "(", ")", ")", "{", "pool", ".", "particles", "[", "i", "]", ".", "move", "(", "x", ",", "y", ")", ";", "}", "}", "}" ]
Move all the particles owned by the specified emitter @param emitter The emitter owning the particles that should be released @param x The amount on the x axis to move the particles @param y The amount on the y axis to move the particles
[ "Move", "all", "the", "particles", "owned", "by", "the", "specified", "emitter" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L607-L614
1,794
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java
ParticleSystem.duplicate
public ParticleSystem duplicate() throws SlickException { for (int i=0;i<emitters.size();i++) { if (!(emitters.get(i) instanceof ConfigurableEmitter)) { throw new SlickException("Only systems contianing configurable emitters can be duplicated"); } } ParticleSystem theCopy = null; try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); ParticleIO.saveConfiguredSystem(bout, this); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); theCopy = ParticleIO.loadConfiguredSystem(bin); } catch (IOException e) { Log.error("Failed to duplicate particle system"); throw new SlickException("Unable to duplicated particle system", e); } return theCopy; }
java
public ParticleSystem duplicate() throws SlickException { for (int i=0;i<emitters.size();i++) { if (!(emitters.get(i) instanceof ConfigurableEmitter)) { throw new SlickException("Only systems contianing configurable emitters can be duplicated"); } } ParticleSystem theCopy = null; try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); ParticleIO.saveConfiguredSystem(bout, this); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); theCopy = ParticleIO.loadConfiguredSystem(bin); } catch (IOException e) { Log.error("Failed to duplicate particle system"); throw new SlickException("Unable to duplicated particle system", e); } return theCopy; }
[ "public", "ParticleSystem", "duplicate", "(", ")", "throws", "SlickException", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "emitters", ".", "size", "(", ")", ";", "i", "++", ")", "{", "if", "(", "!", "(", "emitters", ".", "get", "(", "i", ")", "instanceof", "ConfigurableEmitter", ")", ")", "{", "throw", "new", "SlickException", "(", "\"Only systems contianing configurable emitters can be duplicated\"", ")", ";", "}", "}", "ParticleSystem", "theCopy", "=", "null", ";", "try", "{", "ByteArrayOutputStream", "bout", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "ParticleIO", ".", "saveConfiguredSystem", "(", "bout", ",", "this", ")", ";", "ByteArrayInputStream", "bin", "=", "new", "ByteArrayInputStream", "(", "bout", ".", "toByteArray", "(", ")", ")", ";", "theCopy", "=", "ParticleIO", ".", "loadConfiguredSystem", "(", "bin", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "Log", ".", "error", "(", "\"Failed to duplicate particle system\"", ")", ";", "throw", "new", "SlickException", "(", "\"Unable to duplicated particle system\"", ",", "e", ")", ";", "}", "return", "theCopy", ";", "}" ]
Create a duplicate of this system. This would have been nicer as a different interface but may cause to much API change headache. Maybe next full version release it should be rethought. TODO: Consider refactor at next point release @return A copy of this particle system @throws SlickException Indicates a failure during copy or a invalid particle system to be duplicated
[ "Create", "a", "duplicate", "of", "this", "system", ".", "This", "would", "have", "been", "nicer", "as", "a", "different", "interface", "but", "may", "cause", "to", "much", "API", "change", "headache", ".", "Maybe", "next", "full", "version", "release", "it", "should", "be", "rethought", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/particles/ParticleSystem.java#L626-L645
1,795
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/opengl/renderer/Renderer.java
Renderer.setRenderer
public static void setRenderer(int type) { switch (type) { case IMMEDIATE_RENDERER: setRenderer(new ImmediateModeOGLRenderer()); return; case VERTEX_ARRAY_RENDERER: setRenderer(new VAOGLRenderer()); return; } throw new RuntimeException("Unknown renderer type: "+type); }
java
public static void setRenderer(int type) { switch (type) { case IMMEDIATE_RENDERER: setRenderer(new ImmediateModeOGLRenderer()); return; case VERTEX_ARRAY_RENDERER: setRenderer(new VAOGLRenderer()); return; } throw new RuntimeException("Unknown renderer type: "+type); }
[ "public", "static", "void", "setRenderer", "(", "int", "type", ")", "{", "switch", "(", "type", ")", "{", "case", "IMMEDIATE_RENDERER", ":", "setRenderer", "(", "new", "ImmediateModeOGLRenderer", "(", ")", ")", ";", "return", ";", "case", "VERTEX_ARRAY_RENDERER", ":", "setRenderer", "(", "new", "VAOGLRenderer", "(", ")", ")", ";", "return", ";", "}", "throw", "new", "RuntimeException", "(", "\"Unknown renderer type: \"", "+", "type", ")", ";", "}" ]
Set the renderer to one of the known types @param type The type of renderer to use
[ "Set", "the", "renderer", "to", "one", "of", "the", "known", "types" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/opengl/renderer/Renderer.java#L32-L43
1,796
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/opengl/renderer/Renderer.java
Renderer.setLineStripRenderer
public static void setLineStripRenderer(int type) { switch (type) { case DEFAULT_LINE_STRIP_RENDERER: setLineStripRenderer(new DefaultLineStripRenderer()); return; case QUAD_BASED_LINE_STRIP_RENDERER: setLineStripRenderer(new QuadBasedLineStripRenderer()); return; } throw new RuntimeException("Unknown line strip renderer type: "+type); }
java
public static void setLineStripRenderer(int type) { switch (type) { case DEFAULT_LINE_STRIP_RENDERER: setLineStripRenderer(new DefaultLineStripRenderer()); return; case QUAD_BASED_LINE_STRIP_RENDERER: setLineStripRenderer(new QuadBasedLineStripRenderer()); return; } throw new RuntimeException("Unknown line strip renderer type: "+type); }
[ "public", "static", "void", "setLineStripRenderer", "(", "int", "type", ")", "{", "switch", "(", "type", ")", "{", "case", "DEFAULT_LINE_STRIP_RENDERER", ":", "setLineStripRenderer", "(", "new", "DefaultLineStripRenderer", "(", ")", ")", ";", "return", ";", "case", "QUAD_BASED_LINE_STRIP_RENDERER", ":", "setLineStripRenderer", "(", "new", "QuadBasedLineStripRenderer", "(", ")", ")", ";", "return", ";", "}", "throw", "new", "RuntimeException", "(", "\"Unknown line strip renderer type: \"", "+", "type", ")", ";", "}" ]
Set the line strip renderer to one of the known types @param type The type of renderer to use
[ "Set", "the", "line", "strip", "renderer", "to", "one", "of", "the", "known", "types" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/opengl/renderer/Renderer.java#L50-L61
1,797
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/geom/Transform.java
Transform.transform
public void transform(float source[], int sourceOffset, float destination[], int destOffset, int numberOfPoints) { //TODO performance can be improved by removing the safety to the destination array float result[] = source == destination ? new float[numberOfPoints * 2] : destination; for(int i=0;i<numberOfPoints * 2;i+=2) { for(int j=0;j<6;j+=3) { result[i + (j / 3)] = source[i + sourceOffset] * matrixPosition[j] + source[i + sourceOffset + 1] * matrixPosition[j + 1] + 1 * matrixPosition[j + 2]; } } if (source == destination) { //for safety of the destination, the results are copied after the entire operation. for(int i=0;i<numberOfPoints * 2;i+=2) { destination[i + destOffset] = result[i]; destination[i + destOffset + 1] = result[i + 1]; } } }
java
public void transform(float source[], int sourceOffset, float destination[], int destOffset, int numberOfPoints) { //TODO performance can be improved by removing the safety to the destination array float result[] = source == destination ? new float[numberOfPoints * 2] : destination; for(int i=0;i<numberOfPoints * 2;i+=2) { for(int j=0;j<6;j+=3) { result[i + (j / 3)] = source[i + sourceOffset] * matrixPosition[j] + source[i + sourceOffset + 1] * matrixPosition[j + 1] + 1 * matrixPosition[j + 2]; } } if (source == destination) { //for safety of the destination, the results are copied after the entire operation. for(int i=0;i<numberOfPoints * 2;i+=2) { destination[i + destOffset] = result[i]; destination[i + destOffset + 1] = result[i + 1]; } } }
[ "public", "void", "transform", "(", "float", "source", "[", "]", ",", "int", "sourceOffset", ",", "float", "destination", "[", "]", ",", "int", "destOffset", ",", "int", "numberOfPoints", ")", "{", "//TODO performance can be improved by removing the safety to the destination array \r", "float", "result", "[", "]", "=", "source", "==", "destination", "?", "new", "float", "[", "numberOfPoints", "*", "2", "]", ":", "destination", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numberOfPoints", "*", "2", ";", "i", "+=", "2", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "6", ";", "j", "+=", "3", ")", "{", "result", "[", "i", "+", "(", "j", "/", "3", ")", "]", "=", "source", "[", "i", "+", "sourceOffset", "]", "*", "matrixPosition", "[", "j", "]", "+", "source", "[", "i", "+", "sourceOffset", "+", "1", "]", "*", "matrixPosition", "[", "j", "+", "1", "]", "+", "1", "*", "matrixPosition", "[", "j", "+", "2", "]", ";", "}", "}", "if", "(", "source", "==", "destination", ")", "{", "//for safety of the destination, the results are copied after the entire operation. \r", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numberOfPoints", "*", "2", ";", "i", "+=", "2", ")", "{", "destination", "[", "i", "+", "destOffset", "]", "=", "result", "[", "i", "]", ";", "destination", "[", "i", "+", "destOffset", "+", "1", "]", "=", "result", "[", "i", "+", "1", "]", ";", "}", "}", "}" ]
Transform the point pairs in the source array and store them in the destination array. All operations will be done before storing the results in the destination. This way the source and destination array can be the same without worry of overwriting information before it is transformed. @param source Array of floats containing the points to be transformed @param sourceOffset Where in the array to start processing @param destination Array of floats to store the results. @param destOffset Where in the array to start storing @param numberOfPoints Number of points to be transformed @throws ArrayIndexOutOfBoundsException if sourceOffset + numberOfPoints * 2 > source.length or the same operation on the destination array
[ "Transform", "the", "point", "pairs", "in", "the", "source", "array", "and", "store", "them", "in", "the", "destination", "array", ".", "All", "operations", "will", "be", "done", "before", "storing", "the", "results", "in", "the", "destination", ".", "This", "way", "the", "source", "and", "destination", "array", "can", "be", "the", "same", "without", "worry", "of", "overwriting", "information", "before", "it", "is", "transformed", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/geom/Transform.java#L92-L109
1,798
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/geom/Transform.java
Transform.concatenate
public Transform concatenate(Transform tx) { float[] mp = new float[9]; float n00 = matrixPosition[0] * tx.matrixPosition[0] + matrixPosition[1] * tx.matrixPosition[3]; float n01 = matrixPosition[0] * tx.matrixPosition[1] + matrixPosition[1] * tx.matrixPosition[4]; float n02 = matrixPosition[0] * tx.matrixPosition[2] + matrixPosition[1] * tx.matrixPosition[5] + matrixPosition[2]; float n10 = matrixPosition[3] * tx.matrixPosition[0] + matrixPosition[4] * tx.matrixPosition[3]; float n11 = matrixPosition[3] * tx.matrixPosition[1] + matrixPosition[4] * tx.matrixPosition[4]; float n12 = matrixPosition[3] * tx.matrixPosition[2] + matrixPosition[4] * tx.matrixPosition[5] + matrixPosition[5]; mp[0] = n00; mp[1] = n01; mp[2] = n02; mp[3] = n10; mp[4] = n11; mp[5] = n12; // // mp[0] = matrixPosition[0] * transform.matrixPosition[0] + matrixPosition[0] * transform.matrixPosition[3] + matrixPosition[0] * transform.matrixPosition[6]; // mp[1] = matrixPosition[1] * transform.matrixPosition[1] + matrixPosition[1] * transform.matrixPosition[4] + matrixPosition[1] * transform.matrixPosition[7]; // mp[2] = matrixPosition[2] * transform.matrixPosition[2] + matrixPosition[2] * transform.matrixPosition[5] + matrixPosition[2] * transform.matrixPosition[8]; // mp[3] = matrixPosition[3] * transform.matrixPosition[0] + matrixPosition[3] * transform.matrixPosition[3] + matrixPosition[3] * transform.matrixPosition[6]; // mp[4] = matrixPosition[4] * transform.matrixPosition[1] + matrixPosition[4] * transform.matrixPosition[4] + matrixPosition[4] * transform.matrixPosition[7]; // mp[5] = matrixPosition[5] * transform.matrixPosition[2] + matrixPosition[5] * transform.matrixPosition[5] + matrixPosition[5] * transform.matrixPosition[8]; // matrixPosition = mp; return this; }
java
public Transform concatenate(Transform tx) { float[] mp = new float[9]; float n00 = matrixPosition[0] * tx.matrixPosition[0] + matrixPosition[1] * tx.matrixPosition[3]; float n01 = matrixPosition[0] * tx.matrixPosition[1] + matrixPosition[1] * tx.matrixPosition[4]; float n02 = matrixPosition[0] * tx.matrixPosition[2] + matrixPosition[1] * tx.matrixPosition[5] + matrixPosition[2]; float n10 = matrixPosition[3] * tx.matrixPosition[0] + matrixPosition[4] * tx.matrixPosition[3]; float n11 = matrixPosition[3] * tx.matrixPosition[1] + matrixPosition[4] * tx.matrixPosition[4]; float n12 = matrixPosition[3] * tx.matrixPosition[2] + matrixPosition[4] * tx.matrixPosition[5] + matrixPosition[5]; mp[0] = n00; mp[1] = n01; mp[2] = n02; mp[3] = n10; mp[4] = n11; mp[5] = n12; // // mp[0] = matrixPosition[0] * transform.matrixPosition[0] + matrixPosition[0] * transform.matrixPosition[3] + matrixPosition[0] * transform.matrixPosition[6]; // mp[1] = matrixPosition[1] * transform.matrixPosition[1] + matrixPosition[1] * transform.matrixPosition[4] + matrixPosition[1] * transform.matrixPosition[7]; // mp[2] = matrixPosition[2] * transform.matrixPosition[2] + matrixPosition[2] * transform.matrixPosition[5] + matrixPosition[2] * transform.matrixPosition[8]; // mp[3] = matrixPosition[3] * transform.matrixPosition[0] + matrixPosition[3] * transform.matrixPosition[3] + matrixPosition[3] * transform.matrixPosition[6]; // mp[4] = matrixPosition[4] * transform.matrixPosition[1] + matrixPosition[4] * transform.matrixPosition[4] + matrixPosition[4] * transform.matrixPosition[7]; // mp[5] = matrixPosition[5] * transform.matrixPosition[2] + matrixPosition[5] * transform.matrixPosition[5] + matrixPosition[5] * transform.matrixPosition[8]; // matrixPosition = mp; return this; }
[ "public", "Transform", "concatenate", "(", "Transform", "tx", ")", "{", "float", "[", "]", "mp", "=", "new", "float", "[", "9", "]", ";", "float", "n00", "=", "matrixPosition", "[", "0", "]", "*", "tx", ".", "matrixPosition", "[", "0", "]", "+", "matrixPosition", "[", "1", "]", "*", "tx", ".", "matrixPosition", "[", "3", "]", ";", "float", "n01", "=", "matrixPosition", "[", "0", "]", "*", "tx", ".", "matrixPosition", "[", "1", "]", "+", "matrixPosition", "[", "1", "]", "*", "tx", ".", "matrixPosition", "[", "4", "]", ";", "float", "n02", "=", "matrixPosition", "[", "0", "]", "*", "tx", ".", "matrixPosition", "[", "2", "]", "+", "matrixPosition", "[", "1", "]", "*", "tx", ".", "matrixPosition", "[", "5", "]", "+", "matrixPosition", "[", "2", "]", ";", "float", "n10", "=", "matrixPosition", "[", "3", "]", "*", "tx", ".", "matrixPosition", "[", "0", "]", "+", "matrixPosition", "[", "4", "]", "*", "tx", ".", "matrixPosition", "[", "3", "]", ";", "float", "n11", "=", "matrixPosition", "[", "3", "]", "*", "tx", ".", "matrixPosition", "[", "1", "]", "+", "matrixPosition", "[", "4", "]", "*", "tx", ".", "matrixPosition", "[", "4", "]", ";", "float", "n12", "=", "matrixPosition", "[", "3", "]", "*", "tx", ".", "matrixPosition", "[", "2", "]", "+", "matrixPosition", "[", "4", "]", "*", "tx", ".", "matrixPosition", "[", "5", "]", "+", "matrixPosition", "[", "5", "]", ";", "mp", "[", "0", "]", "=", "n00", ";", "mp", "[", "1", "]", "=", "n01", ";", "mp", "[", "2", "]", "=", "n02", ";", "mp", "[", "3", "]", "=", "n10", ";", "mp", "[", "4", "]", "=", "n11", ";", "mp", "[", "5", "]", "=", "n12", ";", "// \t\r", "// mp[0] = matrixPosition[0] * transform.matrixPosition[0] + matrixPosition[0] * transform.matrixPosition[3] + matrixPosition[0] * transform.matrixPosition[6]; \r", "// mp[1] = matrixPosition[1] * transform.matrixPosition[1] + matrixPosition[1] * transform.matrixPosition[4] + matrixPosition[1] * transform.matrixPosition[7];\r", "// mp[2] = matrixPosition[2] * transform.matrixPosition[2] + matrixPosition[2] * transform.matrixPosition[5] + matrixPosition[2] * transform.matrixPosition[8]; \r", "// mp[3] = matrixPosition[3] * transform.matrixPosition[0] + matrixPosition[3] * transform.matrixPosition[3] + matrixPosition[3] * transform.matrixPosition[6]; \r", "// mp[4] = matrixPosition[4] * transform.matrixPosition[1] + matrixPosition[4] * transform.matrixPosition[4] + matrixPosition[4] * transform.matrixPosition[7];\r", "// mp[5] = matrixPosition[5] * transform.matrixPosition[2] + matrixPosition[5] * transform.matrixPosition[5] + matrixPosition[5] * transform.matrixPosition[8]; \r", "// \r", "matrixPosition", "=", "mp", ";", "return", "this", ";", "}" ]
Update this Transform by concatenating the given Transform to this one. @param tx The Transfrom to concatenate to this one. @return The resulting Transform
[ "Update", "this", "Transform", "by", "concatenating", "the", "given", "Transform", "to", "this", "one", "." ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/geom/Transform.java#L117-L141
1,799
nguillaumin/slick2d-maven
slick2d-core/src/main/java/org/newdawn/slick/geom/Transform.java
Transform.createRotateTransform
public static Transform createRotateTransform(float angle) { return new Transform((float)FastTrig.cos(angle), -(float)FastTrig.sin(angle), 0, (float)FastTrig.sin(angle), (float)FastTrig.cos(angle), 0); }
java
public static Transform createRotateTransform(float angle) { return new Transform((float)FastTrig.cos(angle), -(float)FastTrig.sin(angle), 0, (float)FastTrig.sin(angle), (float)FastTrig.cos(angle), 0); }
[ "public", "static", "Transform", "createRotateTransform", "(", "float", "angle", ")", "{", "return", "new", "Transform", "(", "(", "float", ")", "FastTrig", ".", "cos", "(", "angle", ")", ",", "-", "(", "float", ")", "FastTrig", ".", "sin", "(", "angle", ")", ",", "0", ",", "(", "float", ")", "FastTrig", ".", "sin", "(", "angle", ")", ",", "(", "float", ")", "FastTrig", ".", "cos", "(", "angle", ")", ",", "0", ")", ";", "}" ]
Create a new rotation Transform @param angle The angle in radians to set the transform. @return The resulting Transform
[ "Create", "a", "new", "rotation", "Transform" ]
8251f88a0ed6a70e726d2468842455cd1f80893f
https://github.com/nguillaumin/slick2d-maven/blob/8251f88a0ed6a70e726d2468842455cd1f80893f/slick2d-core/src/main/java/org/newdawn/slick/geom/Transform.java#L172-L174