Java Code Examples for java.nio.ShortBuffer#position()
The following examples show how to use
java.nio.ShortBuffer#position() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Image.java From JavaAV with GNU General Public License v2.0 | 6 votes |
public static void copy(ShortBuffer srcBuf, int srcStep, ShortBuffer dstBuf, int dstStep, boolean signed) { int w = Math.min(srcStep, dstStep); int srcLine = srcBuf.position(); int dstLine = dstBuf.position(); while (srcLine < srcBuf.capacity() && dstLine < dstBuf.capacity()) { srcBuf.position(srcLine); dstBuf.position(dstLine); w = Math.min(Math.min(w, srcBuf.remaining()), dstBuf.remaining()); for (int x = 0; x < w; x++) { int in = signed ? srcBuf.get() : srcBuf.get() & 0xFFFF; short out = (short) in; dstBuf.put(out); } srcLine += srcStep; dstLine += dstStep; } }
Example 2
Source File: HelloGlobe.java From CPE552-Java with GNU General Public License v3.0 | 6 votes |
private ShortBuffer getElementBuffer(float radius, short rings, short sectors) { float R = 1f / (float) (rings - 1); float S = 1f / (float) (sectors - 1); short r, s; float x, y, z; ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(rings * sectors * 6); for (r = 0; r < rings - 1; r++) { for (s = 0; s < sectors - 1; s++) { elementBuffer.put((short) (r * sectors + s)); elementBuffer.put((short) (r * sectors + (s + 1))); elementBuffer.put((short) ((r + 1) * sectors + (s + 1))); elementBuffer.put((short) ((r + 1) * sectors + (s + 1))); elementBuffer.put((short) (r * sectors + s)); // elementBuffer.put((short) (r * sectors + (s + 1))); elementBuffer.put((short) ((r + 1) * sectors + s)); } } elementBuffer.position(0); return elementBuffer; }
Example 3
Source File: BufferUtils.java From Ultraino with MIT License | 6 votes |
public static ShortBuffer ensureLargeEnough(ShortBuffer buffer, int required) { if (buffer != null) { buffer.limit(buffer.capacity()); } if (buffer == null || (buffer.remaining() < required)) { int position = (buffer != null ? buffer.position() : 0); ShortBuffer newVerts = createShortBuffer(position + required); if (buffer != null) { buffer.flip(); newVerts.put(buffer); newVerts.position(position); } buffer = newVerts; } return buffer; }
Example 4
Source File: FinalPcmAudioFilter.java From lavaplayer with Apache License 2.0 | 6 votes |
@Override public void process(ShortBuffer buffer) throws InterruptedException { if (ignoredFrames > 0) { long skipped = Math.min(buffer.remaining(), ignoredFrames); buffer.position(buffer.position() + (int) skipped); ignoredFrames -= skipped; } ShortBuffer local = buffer.duplicate(); while (buffer.remaining() > 0) { int chunk = Math.min(buffer.remaining(), frameBuffer.remaining()); local.position(buffer.position()); local.limit(local.position() + chunk); frameBuffer.put(local); dispatch(); buffer.position(buffer.position() + chunk); } }
Example 5
Source File: TrueTypeFont.java From Bytecoder with Apache License 2.0 | 5 votes |
protected void initAllNames(int requestedID, HashSet<String> names) { byte[] name = new byte[256]; ByteBuffer buffer = getTableBuffer(nameTag); if (buffer != null) { ShortBuffer sbuffer = buffer.asShortBuffer(); sbuffer.get(); // format - not needed. short numRecords = sbuffer.get(); /* The name table uses unsigned shorts. Many of these * are known small values that fit in a short. * The values that are sizes or offsets into the table could be * greater than 32767, so read and store those as ints */ int stringPtr = ((int) sbuffer.get()) & 0xffff; for (int i=0; i<numRecords; i++) { short platformID = sbuffer.get(); if (platformID != MS_PLATFORM_ID) { sbuffer.position(sbuffer.position()+5); continue; // skip over this record. } short encodingID = sbuffer.get(); short langID = sbuffer.get(); short nameID = sbuffer.get(); int nameLen = ((int) sbuffer.get()) & 0xffff; int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr; if (nameID == requestedID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); names.add(makeString(name, nameLen, platformID, encodingID)); } } } }
Example 6
Source File: TrueTypeFont.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
protected void initAllNames(int requestedID, HashSet names) { byte[] name = new byte[256]; ByteBuffer buffer = getTableBuffer(nameTag); if (buffer != null) { ShortBuffer sbuffer = buffer.asShortBuffer(); sbuffer.get(); // format - not needed. short numRecords = sbuffer.get(); /* The name table uses unsigned shorts. Many of these * are known small values that fit in a short. * The values that are sizes or offsets into the table could be * greater than 32767, so read and store those as ints */ int stringPtr = ((int) sbuffer.get()) & 0xffff; for (int i=0; i<numRecords; i++) { short platformID = sbuffer.get(); if (platformID != MS_PLATFORM_ID) { sbuffer.position(sbuffer.position()+5); continue; // skip over this record. } short encodingID = sbuffer.get(); short langID = sbuffer.get(); short nameID = sbuffer.get(); int nameLen = ((int) sbuffer.get()) & 0xffff; int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr; if (nameID == requestedID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); names.add(makeString(name, nameLen, encodingID)); } } } }
Example 7
Source File: BufferUtils.java From In77Camera with MIT License | 5 votes |
public static ShortBuffer getShortBuffer(final short[] array, int offset){ ShortBuffer bb=ByteBuffer.allocateDirect( array.length * SHORT_SIZE_BYTES) .order(ByteOrder.nativeOrder()) .asShortBuffer() .put(array); bb.position(offset); return bb; }
Example 8
Source File: TrueTypeFont.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
protected void initAllNames(int requestedID, HashSet names) { byte[] name = new byte[256]; ByteBuffer buffer = getTableBuffer(nameTag); if (buffer != null) { ShortBuffer sbuffer = buffer.asShortBuffer(); sbuffer.get(); // format - not needed. short numRecords = sbuffer.get(); /* The name table uses unsigned shorts. Many of these * are known small values that fit in a short. * The values that are sizes or offsets into the table could be * greater than 32767, so read and store those as ints */ int stringPtr = ((int) sbuffer.get()) & 0xffff; for (int i=0; i<numRecords; i++) { short platformID = sbuffer.get(); if (platformID != MS_PLATFORM_ID) { sbuffer.position(sbuffer.position()+5); continue; // skip over this record. } short encodingID = sbuffer.get(); short langID = sbuffer.get(); short nameID = sbuffer.get(); int nameLen = ((int) sbuffer.get()) & 0xffff; int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr; if (nameID == requestedID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); names.add(makeString(name, nameLen, encodingID)); } } } }
Example 9
Source File: DOMOutputCapsule.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void write(ShortBuffer value, String name, ShortBuffer defVal) throws IOException { if (value == null) { return; } if (value.equals(defVal)) { return; } Element el = appendElement(name); el.setAttribute("size", String.valueOf(value.limit())); StringBuilder buf = new StringBuilder(); int pos = value.position(); value.rewind(); int ctr = 0; while (value.hasRemaining()) { ctr++; buf.append(value.get()); buf.append(" "); } if (ctr != value.limit()) { throw new IOException("'" + name + "' buffer contention resulted in write data consistency. " + ctr + " values written when should have written " + value.limit()); } if (buf.length() > 0) { //remove last space buf.setLength(buf.length() - 1); } value.position(pos); el.setAttribute(dataAttributeName, buf.toString()); currentElement = (Element) el.getParentNode(); }
Example 10
Source File: TrueTypeFont.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
protected void initAllNames(int requestedID, HashSet names) { byte[] name = new byte[256]; ByteBuffer buffer = getTableBuffer(nameTag); if (buffer != null) { ShortBuffer sbuffer = buffer.asShortBuffer(); sbuffer.get(); // format - not needed. short numRecords = sbuffer.get(); /* The name table uses unsigned shorts. Many of these * are known small values that fit in a short. * The values that are sizes or offsets into the table could be * greater than 32767, so read and store those as ints */ int stringPtr = ((int) sbuffer.get()) & 0xffff; for (int i=0; i<numRecords; i++) { short platformID = sbuffer.get(); if (platformID != MS_PLATFORM_ID) { sbuffer.position(sbuffer.position()+5); continue; // skip over this record. } short encodingID = sbuffer.get(); short langID = sbuffer.get(); short nameID = sbuffer.get(); int nameLen = ((int) sbuffer.get()) & 0xffff; int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr; if (nameID == requestedID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); names.add(makeString(name, nameLen, encodingID)); } } } }
Example 11
Source File: TrueTypeFont.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
protected void initAllNames(int requestedID, HashSet<String> names) { byte[] name = new byte[256]; ByteBuffer buffer = getTableBuffer(nameTag); if (buffer != null) { ShortBuffer sbuffer = buffer.asShortBuffer(); sbuffer.get(); // format - not needed. short numRecords = sbuffer.get(); /* The name table uses unsigned shorts. Many of these * are known small values that fit in a short. * The values that are sizes or offsets into the table could be * greater than 32767, so read and store those as ints */ int stringPtr = ((int) sbuffer.get()) & 0xffff; for (int i=0; i<numRecords; i++) { short platformID = sbuffer.get(); if (platformID != MS_PLATFORM_ID) { sbuffer.position(sbuffer.position()+5); continue; // skip over this record. } short encodingID = sbuffer.get(); short langID = sbuffer.get(); short nameID = sbuffer.get(); int nameLen = ((int) sbuffer.get()) & 0xffff; int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr; if (nameID == requestedID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); names.add(makeString(name, nameLen, platformID, encodingID)); } } } }
Example 12
Source File: TrueTypeFont.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
protected void initNames() { byte[] name = new byte[256]; ByteBuffer buffer = getTableBuffer(nameTag); if (buffer != null) { ShortBuffer sbuffer = buffer.asShortBuffer(); sbuffer.get(); // format - not needed. short numRecords = sbuffer.get(); /* The name table uses unsigned shorts. Many of these * are known small values that fit in a short. * The values that are sizes or offsets into the table could be * greater than 32767, so read and store those as ints */ int stringPtr = sbuffer.get() & 0xffff; nameLocale = sun.awt.SunToolkit.getStartupLocale(); short nameLocaleID = getLCIDFromLocale(nameLocale); for (int i=0; i<numRecords; i++) { short platformID = sbuffer.get(); if (platformID != MS_PLATFORM_ID) { sbuffer.position(sbuffer.position()+5); continue; // skip over this record. } short encodingID = sbuffer.get(); short langID = sbuffer.get(); short nameID = sbuffer.get(); int nameLen = ((int) sbuffer.get()) & 0xffff; int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr; String tmpName = null; switch (nameID) { case FAMILY_NAME_ID: if (familyName == null || langID == ENGLISH_LOCALE_ID || langID == nameLocaleID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); tmpName = makeString(name, nameLen, encodingID); if (familyName == null || langID == ENGLISH_LOCALE_ID){ familyName = tmpName; } if (langID == nameLocaleID) { localeFamilyName = tmpName; } } /* for (int ii=0;ii<nameLen;ii++) { int val = (int)name[ii]&0xff; System.err.print(Integer.toHexString(val)+ " "); } System.err.println(); System.err.println("familyName="+familyName + " nameLen="+nameLen+ " langID="+langID+ " eid="+encodingID + " str len="+familyName.length()); */ break; case FULL_NAME_ID: if (fullName == null || langID == ENGLISH_LOCALE_ID || langID == nameLocaleID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); tmpName = makeString(name, nameLen, encodingID); if (fullName == null || langID == ENGLISH_LOCALE_ID) { fullName = tmpName; } if (langID == nameLocaleID) { localeFullName = tmpName; } } break; } } if (localeFamilyName == null) { localeFamilyName = familyName; } if (localeFullName == null) { localeFullName = fullName; } } }
Example 13
Source File: MDDome3D.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 4 votes |
public static void generateDome(float radius, int sectors, float degreeY, boolean isUpper, MDDome3D object3D) { final float PI = (float) Math.PI; final float PI_2 = (float) (Math.PI / 2); float percent = degreeY / 360; int rings = sectors >> 1; float R = 1f/rings; float S = 1f/sectors; short r, s; float x, y, z; int lenRings = (int) (rings * percent) + 1; int lenSectors = sectors + 1; int numPoint = lenRings * lenSectors; float[] vertexs = new float[numPoint * 3]; float[] texcoords = new float[numPoint * 2]; short[] indices = new short[numPoint * 6]; int upper = isUpper ? 1 : -1; int t = 0, v = 0; for(r = 0; r < lenRings; r++) { for(s = 0; s < lenSectors; s++) { x = (float) (Math.cos( 2 * PI * s * S ) * Math.sin( PI * r * R )) * upper; y = (float) Math.sin( -PI_2 + PI * r * R ) * -upper; z = (float) (Math.sin( 2 * PI * s * S ) * Math.sin( PI * r * R )); float a = (float) (Math.cos( 2 * PI * s * S) * r * R / percent)/2.0f + 0.5f; float b = (float) (Math.sin( 2 * PI * s * S) * r * R / percent)/2.0f + 0.5f; texcoords[t++] = b; texcoords[t++] = a; vertexs[v++] = x * radius; vertexs[v++] = y * radius; vertexs[v++] = z * radius; } } int counter = 0; for(r = 0; r < lenRings - 1; r++){ for(s = 0; s < lenSectors - 1; s++) { indices[counter++] = (short) (r * lenSectors + s); //(a) indices[counter++] = (short) ((r+1) * lenSectors + (s)); //(b) indices[counter++] = (short) ((r) * lenSectors + (s+1)); // (c) indices[counter++] = (short) ((r) * lenSectors + (s+1)); // (c) indices[counter++] = (short) ((r+1) * lenSectors + (s)); //(b) indices[counter++] = (short) ((r+1) * lenSectors + (s+1)); // (d) } } // initialize vertex byte buffer for shape coordinates ByteBuffer bb = ByteBuffer.allocateDirect( // (# of coordinate values * 4 bytes per float) vertexs.length * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer vertexBuffer = bb.asFloatBuffer(); vertexBuffer.put(vertexs); vertexBuffer.position(0); // initialize vertex byte buffer for shape coordinates ByteBuffer cc = ByteBuffer.allocateDirect( texcoords.length * 4); cc.order(ByteOrder.nativeOrder()); FloatBuffer texBuffer = cc.asFloatBuffer(); texBuffer.put(texcoords); texBuffer.position(0); // initialize byte buffer for the draw list ByteBuffer dlb = ByteBuffer.allocateDirect( // (# of coordinate values * 2 bytes per short) indices.length * 2); dlb.order(ByteOrder.nativeOrder()); ShortBuffer indexBuffer = dlb.asShortBuffer(); indexBuffer.put(indices); indexBuffer.position(0); object3D.setIndicesBuffer(indexBuffer); object3D.setTexCoordinateBuffer(0,texBuffer); object3D.setTexCoordinateBuffer(1,texBuffer); object3D.setVerticesBuffer(0,vertexBuffer); object3D.setVerticesBuffer(1,vertexBuffer); object3D.setNumIndices(indices.length); object3D.texCoordinates = texcoords; }
Example 14
Source File: Minimap.java From settlers-remake with MIT License | 4 votes |
public void draw(GLDrawContext context, float x, float y) { boolean imageWasCreatedJustNow = false; try { if(geometry == null || !geometry.isValid()) { geometry = context.storeGeometry( new float[] {0, 0, 0, 0, width, 0, 1, 0,(stride + 1) * width, height, 1, 1, stride * width, height, 0, 1,}, EGeometryFormatType.Texture2D, false, "minimap"); lineGeometry = context.generateGeometry(6, EGeometryFormatType.VertexOnly2D, true, "minimap-frame"); } if(updateGeometry) { lineBfr.asFloatBuffer().put(miniMapShapeCalculator.getMiniMapShapeNodes(), 0, 12); context.updateGeometryAt(lineGeometry, 0, lineBfr); replaceGeometryValue(context, 4, width); replaceGeometryValue(context, 8, (stride + 1) * width); replaceGeometryValue(context, 9, height); replaceGeometryValue(context, 12, stride * width); replaceGeometryValue(context, 13, height); updateGeometry = false; } synchronized (updateMutex) { if (!imageIsValid || texture == null || !texture.isValid()) { imageWasCreatedJustNow = true; if (texture != null && texture.isValid()) { context.deleteTexture(texture); texture = null; } ShortBuffer data = ByteBuffer.allocateDirect(width * height * 2) .order(ByteOrder.nativeOrder()).asShortBuffer(); for (int i = 0; i < width * height; i++) { data.put(LineLoader.BLACK); } data.position(0); texture = context.generateTexture(width, height, data, "minimap"); updatedLines.clear(); imageIsValid = true; } if (!updatedLines.isEmpty()) { ShortBuffer currData = ByteBuffer.allocateDirect(width * 2) .order(ByteOrder.nativeOrder()).asShortBuffer(); for (Integer currLine : updatedLines) { currData.position(0); currData.put(buffer[currLine]); currData.position(0); context.updateTexture(texture, 0, currLine, width, 1, currData ); } updatedLines.clear(); } updateMutex.notifyAll(); } context.draw2D(geometry, texture, EGeometryType.Quad, 0, 4, x, y, 0, 1, 1, 1, null, 1); drawViewMark(context, x, y); } catch (IllegalBufferException e) { if (imageWasCreatedJustNow) { // TODO: Error reporting e.printStackTrace(); } else { // Retry with a new image. synchronized (updateMutex) { imageIsValid = false; } draw(context, x, y); } } }
Example 15
Source File: TrueTypeFont.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
protected void initNames() { byte[] name = new byte[256]; ByteBuffer buffer = getTableBuffer(nameTag); if (buffer != null) { ShortBuffer sbuffer = buffer.asShortBuffer(); sbuffer.get(); // format - not needed. short numRecords = sbuffer.get(); /* The name table uses unsigned shorts. Many of these * are known small values that fit in a short. * The values that are sizes or offsets into the table could be * greater than 32767, so read and store those as ints */ int stringPtr = sbuffer.get() & 0xffff; nameLocale = sun.awt.SunToolkit.getStartupLocale(); short nameLocaleID = getLCIDFromLocale(nameLocale); for (int i=0; i<numRecords; i++) { short platformID = sbuffer.get(); if (platformID != MS_PLATFORM_ID) { sbuffer.position(sbuffer.position()+5); continue; // skip over this record. } short encodingID = sbuffer.get(); short langID = sbuffer.get(); short nameID = sbuffer.get(); int nameLen = ((int) sbuffer.get()) & 0xffff; int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr; String tmpName = null; switch (nameID) { case FAMILY_NAME_ID: if (familyName == null || langID == ENGLISH_LOCALE_ID || langID == nameLocaleID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); tmpName = makeString(name, nameLen, encodingID); if (familyName == null || langID == ENGLISH_LOCALE_ID){ familyName = tmpName; } if (langID == nameLocaleID) { localeFamilyName = tmpName; } } /* for (int ii=0;ii<nameLen;ii++) { int val = (int)name[ii]&0xff; System.err.print(Integer.toHexString(val)+ " "); } System.err.println(); System.err.println("familyName="+familyName + " nameLen="+nameLen+ " langID="+langID+ " eid="+encodingID + " str len="+familyName.length()); */ break; case FULL_NAME_ID: if (fullName == null || langID == ENGLISH_LOCALE_ID || langID == nameLocaleID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); tmpName = makeString(name, nameLen, encodingID); if (fullName == null || langID == ENGLISH_LOCALE_ID) { fullName = tmpName; } if (langID == nameLocaleID) { localeFullName = tmpName; } } break; } } if (localeFamilyName == null) { localeFamilyName = familyName; } if (localeFullName == null) { localeFullName = fullName; } } }
Example 16
Source File: RenderBucket.java From trekarta with GNU General Public License v3.0 | 4 votes |
protected void compileVertexItems(ShortBuffer vboData) { /* keep offset of layer data in vbo */ vertexOffset = vboData.position() * RenderBuckets.SHORT_BYTES; vertexItems.compile(vboData); }
Example 17
Source File: TrueTypeFont.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
protected String lookupName(short findLocaleID, int findNameID) { String foundName = null; byte[] name = new byte[1024]; ByteBuffer buffer = getTableBuffer(nameTag); if (buffer != null) { ShortBuffer sbuffer = buffer.asShortBuffer(); sbuffer.get(); // format - not needed. short numRecords = sbuffer.get(); /* The name table uses unsigned shorts. Many of these * are known small values that fit in a short. * The values that are sizes or offsets into the table could be * greater than 32767, so read and store those as ints */ int stringPtr = ((int) sbuffer.get()) & 0xffff; for (int i=0; i<numRecords; i++) { short platformID = sbuffer.get(); if (platformID != MS_PLATFORM_ID) { sbuffer.position(sbuffer.position()+5); continue; // skip over this record. } short encodingID = sbuffer.get(); short langID = sbuffer.get(); short nameID = sbuffer.get(); int nameLen = ((int) sbuffer.get()) & 0xffff; int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr; if (nameID == findNameID && ((foundName == null && langID == ENGLISH_LOCALE_ID) || langID == findLocaleID)) { buffer.position(namePtr); buffer.get(name, 0, nameLen); foundName = makeString(name, nameLen, encodingID); if (langID == findLocaleID) { return foundName; } } } } return foundName; }
Example 18
Source File: TrueTypeFont.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
protected void initNames() { byte[] name = new byte[256]; ByteBuffer buffer = getTableBuffer(nameTag); if (buffer != null) { ShortBuffer sbuffer = buffer.asShortBuffer(); sbuffer.get(); // format - not needed. short numRecords = sbuffer.get(); /* The name table uses unsigned shorts. Many of these * are known small values that fit in a short. * The values that are sizes or offsets into the table could be * greater than 32767, so read and store those as ints */ int stringPtr = sbuffer.get() & 0xffff; nameLocale = sun.awt.SunToolkit.getStartupLocale(); short nameLocaleID = getLCIDFromLocale(nameLocale); for (int i=0; i<numRecords; i++) { short platformID = sbuffer.get(); if (platformID != MS_PLATFORM_ID) { sbuffer.position(sbuffer.position()+5); continue; // skip over this record. } short encodingID = sbuffer.get(); short langID = sbuffer.get(); short nameID = sbuffer.get(); int nameLen = ((int) sbuffer.get()) & 0xffff; int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr; String tmpName = null; switch (nameID) { case FAMILY_NAME_ID: if (familyName == null || langID == ENGLISH_LOCALE_ID || langID == nameLocaleID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); tmpName = makeString(name, nameLen, encodingID); if (familyName == null || langID == ENGLISH_LOCALE_ID){ familyName = tmpName; } if (langID == nameLocaleID) { localeFamilyName = tmpName; } } /* for (int ii=0;ii<nameLen;ii++) { int val = (int)name[ii]&0xff; System.err.print(Integer.toHexString(val)+ " "); } System.err.println(); System.err.println("familyName="+familyName + " nameLen="+nameLen+ " langID="+langID+ " eid="+encodingID + " str len="+familyName.length()); */ break; case FULL_NAME_ID: if (fullName == null || langID == ENGLISH_LOCALE_ID || langID == nameLocaleID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); tmpName = makeString(name, nameLen, encodingID); if (fullName == null || langID == ENGLISH_LOCALE_ID) { fullName = tmpName; } if (langID == nameLocaleID) { localeFullName = tmpName; } } break; } } if (localeFamilyName == null) { localeFamilyName = familyName; } if (localeFullName == null) { localeFullName = fullName; } } }
Example 19
Source File: TrueTypeFont.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
protected void initNames() { byte[] name = new byte[256]; ByteBuffer buffer = getTableBuffer(nameTag); if (buffer != null) { ShortBuffer sbuffer = buffer.asShortBuffer(); sbuffer.get(); // format - not needed. short numRecords = sbuffer.get(); /* The name table uses unsigned shorts. Many of these * are known small values that fit in a short. * The values that are sizes or offsets into the table could be * greater than 32767, so read and store those as ints */ int stringPtr = sbuffer.get() & 0xffff; nameLocale = sun.awt.SunToolkit.getStartupLocale(); short nameLocaleID = getLCIDFromLocale(nameLocale); for (int i=0; i<numRecords; i++) { short platformID = sbuffer.get(); if (platformID != MS_PLATFORM_ID) { sbuffer.position(sbuffer.position()+5); continue; // skip over this record. } short encodingID = sbuffer.get(); short langID = sbuffer.get(); short nameID = sbuffer.get(); int nameLen = ((int) sbuffer.get()) & 0xffff; int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr; String tmpName = null; switch (nameID) { case FAMILY_NAME_ID: if (familyName == null || langID == ENGLISH_LOCALE_ID || langID == nameLocaleID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); tmpName = makeString(name, nameLen, encodingID); if (familyName == null || langID == ENGLISH_LOCALE_ID){ familyName = tmpName; } if (langID == nameLocaleID) { localeFamilyName = tmpName; } } /* for (int ii=0;ii<nameLen;ii++) { int val = (int)name[ii]&0xff; System.err.print(Integer.toHexString(val)+ " "); } System.err.println(); System.err.println("familyName="+familyName + " nameLen="+nameLen+ " langID="+langID+ " eid="+encodingID + " str len="+familyName.length()); */ break; case FULL_NAME_ID: if (fullName == null || langID == ENGLISH_LOCALE_ID || langID == nameLocaleID) { buffer.position(namePtr); buffer.get(name, 0, nameLen); tmpName = makeString(name, nameLen, encodingID); if (fullName == null || langID == ENGLISH_LOCALE_ID) { fullName = tmpName; } if (langID == nameLocaleID) { localeFullName = tmpName; } } break; } } if (localeFamilyName == null) { localeFamilyName = familyName; } if (localeFullName == null) { localeFullName = fullName; } } }
Example 20
Source File: MDPlane.java From MD360Player4Android with Apache License 2.0 | 4 votes |
private void generateMesh(MDAbsObject3D object3D){ int rows = getNumRow(); int columns = getNumColumn(); short r, s; float[] vertexs = generateVertex(); float[] texcoords = generateTexcoords(); short[] indices = new short[getNumPoint() * 6]; int counter = 0; int sectorsPlusOne = columns + 1; for(r = 0; r < rows; r++){ for(s = 0; s < columns; s++) { short k0 = (short) ((r) * sectorsPlusOne + (s+1)); // (c) short k1 = (short) ((r+1) * sectorsPlusOne + (s)); //(b) short k2 = (short) (r * sectorsPlusOne + s); //(a); short k3 = (short) ((r) * sectorsPlusOne + (s+1)); // (c) short k4 = (short) ((r+1) * sectorsPlusOne + (s+1)); // (d) short k5 = (short) ((r+1) * sectorsPlusOne + (s)); //(b) indices[counter++] = k0; indices[counter++] = k1; indices[counter++] = k2; indices[counter++] = k3; indices[counter++] = k4; indices[counter++] = k5; } } // initialize vertex byte buffer for shape coordinates ByteBuffer bb = ByteBuffer.allocateDirect( // (# of coordinate values * 4 bytes per float) vertexs.length * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer vertexBuffer = bb.asFloatBuffer(); vertexBuffer.put(vertexs); vertexBuffer.position(0); // initialize vertex byte buffer for shape coordinates ByteBuffer cc = ByteBuffer.allocateDirect( texcoords.length * 4); cc.order(ByteOrder.nativeOrder()); FloatBuffer texBuffer = cc.asFloatBuffer(); texBuffer.put(texcoords); texBuffer.position(0); // initialize byte buffer for the draw list ByteBuffer dlb = ByteBuffer.allocateDirect( // (# of coordinate values * 2 bytes per short) indices.length * 2); dlb.order(ByteOrder.nativeOrder()); ShortBuffer indexBuffer = dlb.asShortBuffer(); indexBuffer.put(indices); indexBuffer.position(0); object3D.setIndicesBuffer(indexBuffer); object3D.setTexCoordinateBuffer(0,texBuffer); object3D.setTexCoordinateBuffer(1,texBuffer); object3D.setVerticesBuffer(0,vertexBuffer); object3D.setVerticesBuffer(1,vertexBuffer); object3D.setNumIndices(indices.length); }