我们可以在android项目中使用任何jar文件(由java代码制成)吗?
我有一个使用如下导入的类:
import java.awt.*;
import java.awt.font.GlyphVector;
import java.awt.font.FontRenderContext;
public class FontEx{
public static void main(String[] args) {
}
}
我们知道Android没有附带java.awt.font.GlyphVector或font.FontRenderContext。
我可以为这个类“FontEx”制作jar文件并将其直接导入到我的android eclipse项目中并使用它吗???
...................................................... ................................ ...................................................... ................................
**package org.newdawn.slick.font;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.font.GlyphMetrics;
import java.awt.font.GlyphVector;
import org.newdawn.slick.Image;
import org.newdawn.slick.UnicodeFont;
/**
* Represents the glyph in a font for a unicode codepoint.
*
* @author Nathan Sweet <[email protected]>
*/
public class Glyph {
/** The code point in which this glyph is found */
private int codePoint;
/** The width of this glyph in pixels */
private short width;
/** The height of this glyph in pixels */
private short height;
/** The offset on the y axis to draw the glyph at */
private short yOffset;
/** True if the glyph isn't defined */
private boolean isMissing;
/** The shape drawn for this glyph */
private Shape shape;
/** The image generated for this glyph */
private Image image;
/**
* Create a new glyph
*
* @param codePoint The code point in which this glyph can be found
* @param bounds The bounds that this glrph can fill
* @param vector The vector this glyph is part of
* @param index The index of this glyph within the vector
* @param unicodeFont The font this glyph forms part of
*/
public Glyph(int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
this.codePoint = codePoint;
GlyphMetrics metrics = vector.getGlyphMetrics(index);
int lsb = (int)metrics.getLSB();
if (lsb > 0) lsb = 0;
int rsb = (int)metrics.getRSB();
if (rsb > 0) rsb = 0;
int glyphWidth = bounds.width - lsb - rsb;
int glyphHeight = bounds.height;
if (glyphWidth > 0 && glyphHeight > 0) {
int padTop = unicodeFont.getPaddingTop();
int padRight = unicodeFont.getPaddingRight();
int padBottom = unicodeFont.getPaddingBottom();
int padLeft = unicodeFont.getPaddingLeft();
int glyphSpacing = 1; // Needed to prevent filtering problems.
width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
}
shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());
isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
/**
* The unicode codepoint the glyph represents.
*
* @return The codepoint the glyph represents
*/
public int getCodePoint () {
return codePoint;
}
/**
* Returns true if the font does not have a glyph for this codepoint.
*
* @return True if this glyph is not defined in the given code point
*/
public boolean isMissing () {
return isMissing;
}
/**
* The width of the glyph's image.
*
* @return The width in pixels of the glyphs image
*/
public int getWidth () {
return width;
}
/**
* The height of the glyph's image.
*
* @return The height in pixels of the glyphs image
*/
public int getHeight () {
return height;
}
/**
* The shape to use to draw this glyph. This is set to null after the glyph is stored
* in a GlyphPage.
*
* @return The shape drawn for this glyph
*/
public Shape getShape () {
return shape;
}
/**
* Set the shape that should be drawn for this glyph
*
* @param shape The shape that should be drawn for this glyph
*/
public void setShape(Shape shape) {
this.shape = shape;
}
/**
* The image to use for this glyph. This is null until after the glyph is stored in a
* GlyphPage.
*
* @return The image that has been generated for this glyph
*/
public Image getImage () {
return image;
}
/**
* Set the image that has been generated for this glyph
*
* @param image The image that has been generated for this glyph
*/
public void setImage(Image image) {
this.image = image;
}
/**
* The distance from drawing y location to top of this glyph, causing the glyph to sit
* on the baseline.
*
* @return The offset on the y axis this glyph should be drawn at
*/
public int getYOffset() {
return yOffset;
}
}**
I have a class which uses imports like:
import java.awt.*;
import java.awt.font.GlyphVector;
import java.awt.font.FontRenderContext;
public class FontEx{
public static void main(String[] args) {
}
}
We know that Android does't come with java.awt.font.GlyphVector or font.FontRenderContext.
Can i make jar file for this class "FontEx" and import it directly in my android eclipse project and use it???
...............................................................................
..................................................................................
**package org.newdawn.slick.font;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.font.GlyphMetrics;
import java.awt.font.GlyphVector;
import org.newdawn.slick.Image;
import org.newdawn.slick.UnicodeFont;
/**
* Represents the glyph in a font for a unicode codepoint.
*
* @author Nathan Sweet <[email protected]>
*/
public class Glyph {
/** The code point in which this glyph is found */
private int codePoint;
/** The width of this glyph in pixels */
private short width;
/** The height of this glyph in pixels */
private short height;
/** The offset on the y axis to draw the glyph at */
private short yOffset;
/** True if the glyph isn't defined */
private boolean isMissing;
/** The shape drawn for this glyph */
private Shape shape;
/** The image generated for this glyph */
private Image image;
/**
* Create a new glyph
*
* @param codePoint The code point in which this glyph can be found
* @param bounds The bounds that this glrph can fill
* @param vector The vector this glyph is part of
* @param index The index of this glyph within the vector
* @param unicodeFont The font this glyph forms part of
*/
public Glyph(int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
this.codePoint = codePoint;
GlyphMetrics metrics = vector.getGlyphMetrics(index);
int lsb = (int)metrics.getLSB();
if (lsb > 0) lsb = 0;
int rsb = (int)metrics.getRSB();
if (rsb > 0) rsb = 0;
int glyphWidth = bounds.width - lsb - rsb;
int glyphHeight = bounds.height;
if (glyphWidth > 0 && glyphHeight > 0) {
int padTop = unicodeFont.getPaddingTop();
int padRight = unicodeFont.getPaddingRight();
int padBottom = unicodeFont.getPaddingBottom();
int padLeft = unicodeFont.getPaddingLeft();
int glyphSpacing = 1; // Needed to prevent filtering problems.
width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
}
shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());
isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
/**
* The unicode codepoint the glyph represents.
*
* @return The codepoint the glyph represents
*/
public int getCodePoint () {
return codePoint;
}
/**
* Returns true if the font does not have a glyph for this codepoint.
*
* @return True if this glyph is not defined in the given code point
*/
public boolean isMissing () {
return isMissing;
}
/**
* The width of the glyph's image.
*
* @return The width in pixels of the glyphs image
*/
public int getWidth () {
return width;
}
/**
* The height of the glyph's image.
*
* @return The height in pixels of the glyphs image
*/
public int getHeight () {
return height;
}
/**
* The shape to use to draw this glyph. This is set to null after the glyph is stored
* in a GlyphPage.
*
* @return The shape drawn for this glyph
*/
public Shape getShape () {
return shape;
}
/**
* Set the shape that should be drawn for this glyph
*
* @param shape The shape that should be drawn for this glyph
*/
public void setShape(Shape shape) {
this.shape = shape;
}
/**
* The image to use for this glyph. This is null until after the glyph is stored in a
* GlyphPage.
*
* @return The image that has been generated for this glyph
*/
public Image getImage () {
return image;
}
/**
* Set the image that has been generated for this glyph
*
* @param image The image that has been generated for this glyph
*/
public void setImage(Image image) {
this.image = image;
}
/**
* The distance from drawing y location to top of this glyph, causing the glyph to sit
* on the baseline.
*
* @return The offset on the y axis this glyph should be drawn at
*/
public int getYOffset() {
return yOffset;
}
}**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 FontEx 类依赖于 GlyphVector 和 FontRenderContext,则不行 - 打包到 jar 文件中不会使该类变得更可用。
If the FontEx class depends on GlyphVector and FontRenderContext, then no - packaging into a jar file won't make the class any more usable.