Esempio n. 1
0
  /**
   * Loads a font based on file path
   *
   * @param String filePath
   * @param float fontSize
   * @param FontStyle fontStyle
   * @throws FontFormatException
   * @throws IOException
   */
  public INFont(String filePath, float fontSize, FontStyle fontStyle)
      throws FontFormatException, IOException {
    File fontFile = new File(filePath);

    this.loadedFont = Font.createFont(Font.TRUETYPE_FONT, fontFile);
    this.loadedFont = this.loadedFont.deriveFont(fontSize);

    this.style = fontStyle;
    this.size = fontSize;

    switch (fontStyle) {
      case BOLD:
        this.loadedFont = this.loadedFont.deriveFont(Font.BOLD);
        break;
      case ITALIC:
        this.loadedFont = this.loadedFont.deriveFont(Font.ITALIC);
        break;
      case PLAIN:
        this.loadedFont = this.loadedFont.deriveFont(Font.PLAIN);
        break;
      case BOLDANDITALIC:
        this.loadedFont = this.loadedFont.deriveFont(Font.BOLD + Font.ITALIC);
        break;
    }
  }
 // renders font characters to be used for text painting in tests (to make font rendering
 // platform-independent)
 public static void main(String[] args) throws Exception {
   Font font =
       Font.createFont(
           Font.TRUETYPE_FONT,
           EditorPaintingTest.class.getResourceAsStream("/fonts/Inconsolata.ttf"));
   BitmapFont bitmapFont = BitmapFont.createFromFont(font);
   bitmapFont.saveToFile(getFontFile());
 }
 /**
  * Loads the Bootstrap font containing the glyphs
  *
  * @param size Desired font size
  * @return Font object for Bootstrap Glyph Font
  * @throws FontFormatException
  * @throws IOException
  */
 private Font loadGlyphFont(float size) throws FontFormatException, IOException {
   Font fontRaw =
       Font.createFont(
           Font.TRUETYPE_FONT,
           this.getClass()
               .getResourceAsStream("/resource/image/glyphicons-halflings-regular.ttf"));
   Font fontBase = fontRaw.deriveFont(16f);
   return fontBase.deriveFont(Font.PLAIN, size);
 }
Esempio n. 4
0
 /**
  * Creates a new TrueType font addressed by Unicode characters. The font will always be embedded.
  *
  * @param ttFile the location of the font on file. The file must end in '.ttf'. The modifiers
  *     after the name are ignored.
  * @param enc the encoding to be applied to this font
  * @param emb true if the font is to be embedded in the PDF
  * @param ttfAfm the font as a <CODE>byte</CODE> array
  * @throws DocumentException the font is invalid
  * @throws IOException the font file could not be read
  */
 TrueTypeFontUnicode(String ttFile, String enc, boolean emb, byte ttfAfm[], boolean forceRead)
     throws DocumentException, IOException {
   // String nameBase = getBaseName(ttFile);
   InputStream is = new FileInputStream(ttFile);
   try {
     javaFont = Font.createFont(Font.TRUETYPE_FONT, is);
   } catch (FontFormatException e) {
     e.printStackTrace();
     throw new IOException(e);
   } finally {
     is.close();
   }
   javaFontContext = new FontRenderContext(null, false, false);
   String nameBase = getBaseName(ttFile);
   String ttcName = getTTCName(nameBase);
   if (nameBase.length() < ttFile.length()) {
     style = ttFile.substring(nameBase.length());
   }
   encoding = enc;
   embedded = emb;
   fileName = ttcName;
   ttcIndex = "";
   if (ttcName.length() < nameBase.length()) ttcIndex = nameBase.substring(ttcName.length() + 1);
   fontType = FONT_TYPE_TTUNI;
   if ((fileName.toLowerCase().endsWith(".ttf")
           || fileName.toLowerCase().endsWith(".otf")
           || fileName.toLowerCase().endsWith(".ttc"))
       && (enc.equals(IDENTITY_H) || enc.equals(IDENTITY_V))
       && emb) {
     process(ttfAfm, forceRead);
     if (os_2.fsType == 2)
       throw new DocumentException(
           MessageLocalization.getComposedMessage(
               "1.cannot.be.embedded.due.to.licensing.restrictions", fileName + style));
     // Sivan
     if (cmap31 == null && !fontSpecific || cmap10 == null && fontSpecific)
       directTextToByte = true;
     // throw new
     // DocumentException(MessageLocalization.getComposedMessage("1.2.does.not.contain.an.usable.cmap", fileName, style));
     if (fontSpecific) {
       fontSpecific = false;
       String tempEncoding = encoding;
       encoding = "";
       createEncoding();
       encoding = tempEncoding;
       fontSpecific = true;
     }
   } else
     throw new DocumentException(
         MessageLocalization.getComposedMessage("1.2.is.not.a.ttf.font.file", fileName, style));
   vertical = enc.endsWith("V");
 }
Esempio n. 5
0
  /**
   * Create a new font data element
   *
   * @param ttf The TTF file to read
   * @param size The size of the new font
   * @throws java.io.IOException Indicates a failure to
   */
  private FontData(InputStream ttf, float size) throws IOException {
    if (ttf.available() > MAX_FILE_SIZE) {
      throw new IOException("Can't load font - too big");
    }
    byte[] data = IOUtils.toByteArray(ttf);
    if (data.length > MAX_FILE_SIZE) {
      throw new IOException("Can't load font - too big");
    }

    this.size = size;
    try {
      javaFont = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(data));
      TTFFile rawFont = new TTFFile();
      if (!rawFont.readFont(new FontFileReader(data))) {
        throw new IOException("Invalid font file");
      }
      upem = rawFont.getUPEM();
      ansiKerning = rawFont.getAnsiKerning();
      charWidth = rawFont.getAnsiWidth();
      fontName = rawFont.getPostScriptName();
      familyName = rawFont.getFamilyName();

      String name = getName();
      System.err.println("Loaded: " + name + " (" + data.length + ")");
      boolean bo = false;
      boolean it = false;
      if (name.indexOf(',') >= 0) {
        name = name.substring(name.indexOf(','));

        if (name.indexOf("Bold") >= 0) {
          bo = true;
        }
        if (name.indexOf("Italic") >= 0) {
          it = true;
        }
      }

      if ((bo & it)) {
        javaFont = javaFont.deriveFont(Font.BOLD | Font.ITALIC);
      } else if (bo) {
        javaFont = javaFont.deriveFont(Font.BOLD);
      } else if (it) {
        javaFont = javaFont.deriveFont(Font.ITALIC);
      }
    } catch (FontFormatException e) {
      IOException x = new IOException("Failed to read font");
      x.initCause(e);
      throw x;
    }
  }
Esempio n. 6
0
  private void addFont(String fontKey, String fontName, float scale) {
    try {
      fontName = fontName.toLowerCase();

      FileInputStream stream = new FileInputStream("data/fonts/ttf/" + fontName + ".ttf");

      Font f = Font.createFont(Font.TRUETYPE_FONT, stream);
      f = f.deriveFont(scale);

      fonts.put(fontKey, f);
      stream.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
    private Font getProductFont() {
      String name = "/fonts/Roboto-Light.ttf";
      URL url = AppUIUtil.class.getResource(name);
      if (url == null) {
        Logger.getInstance(AppUIUtil.class).warn("Resource missing: " + name);
      } else {

        try {
          InputStream is = url.openStream();
          try {
            return Font.createFont(Font.TRUETYPE_FONT, is);
          } finally {
            is.close();
          }
        } catch (Throwable t) {
          Logger.getInstance(AppUIUtil.class).warn("Cannot load font: " + url, t);
        }
      }
      return UIUtil.getLabelFont();
    }
  private void registerFont(String name) {
    if (isHeadlessEnvironment()) return;

    InputStream is = null;
    try {
      is = getClass().getResourceAsStream(name);
      final Font font = Font.createFont(Font.TRUETYPE_FONT, is);
      GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
    } catch (Exception e) {
      LOG.info(e);
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException e) {
          LOG.error(e);
        }
      }
    }
  }
Esempio n. 9
0
 @NotNull
 private static Font getFontWithLigaturesEnabled(Font font) {
   if (SystemInfo.isMac) {
     // Ligatures don't work on Mac for fonts loaded natively, so we need to locate and load font
     // manually
     File fontFile = findFileForFont(font, true);
     if (fontFile == null && font.getStyle() != Font.PLAIN)
       fontFile = findFileForFont(font.deriveFont(Font.PLAIN), true);
     if (fontFile == null) fontFile = findFileForFont(font, false);
     if (fontFile == null) return font;
     try {
       font =
           Font.createFont(Font.TRUETYPE_FONT, fontFile)
               .deriveFont(font.getStyle(), font.getSize());
     } catch (Exception e) {
       return font;
     }
   }
   return font.deriveFont(
       Collections.singletonMap(TextAttribute.LIGATURES, TextAttribute.LIGATURES_ON));
 }
Esempio n. 10
0
  public shit() {
    this.addWindowListener(this);
    setSize(1280, 720);
    setVisible(true);

    r = new Random();
    //		ap = new AudioPlayer();//THIS SHIT DOESN'T WORK WHAT THE F**K DEHOWE
    timer = System.currentTimeMillis();
    options.add("");
    options.add("");
    options.add(""); // These 3 lines are to populate options.
    state = 1; // The first line will always be a story panel so the state is 1.
    try {
      URL url = getClass().getResource("options.png");
      obox = ImageIO.read((url));
      url = getClass().getResource("Text Boxes.png");
      textBox = ImageIO.read(url); // reads in the text boxes file.
      p = new parser("Introduction.txt"); // reads in the story file.
      progress(); // the function that calls going through to the next line
    } catch (IOException e) {
      e.printStackTrace();
    }

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
      URL url = getClass().getResource("sspr.ttf");
      ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, url.openStream()));
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    resize(SCREENWIDTH, SCREENHEIGHT); // Makes the applet the size we want it
    addMouseListener(this); // Lets us use mouse
    addKeyListener(this); // Lets us use keyboard

    Thread t = new Thread(this);
    t.start();
  }
Esempio n. 11
0
  public MancalaPanel(LetsPlayMancala game) {

    // ------------------------------------------------------------------------------
    // Import font "Belta Regular"
    // -----------------------------------------------------------------------------
    try {
      InputStream in = MancalaPanel.class.getResourceAsStream("belta-regular.ttf");
      Font font = Font.createFont(Font.TRUETYPE_FONT, in);
    } catch (Exception ex) {
      System.out.println("Font couldn't be loaded.");
    }

    // ----------------------------------------------------------------------------
    // Set background image
    // ----------------------------------------------------------------------------
    imageFile = "/Images/GameBackground.png";
    this.game = game;
    SMALL_PIT_COUNT = 12;

    setLayout(new BorderLayout());

    add(northWindowPanel(), BorderLayout.NORTH);
    add(westWindowPanel(), BorderLayout.WEST);
    add(makeBoardPanel(), BorderLayout.CENTER);
    add(eastWindowPanel(), BorderLayout.EAST);
    add(southWindowPanel(), BorderLayout.SOUTH);

    winners = new LinkedStack<String>();
    winnersLabel = new JLabel();

    resultFrame = new JFrame();
    boardResultPanel = new BkImagePanel("/Images/board2.png");
    resultNorth = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 50));
    resultNorth.setOpaque(false);
    resultCenter = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
    resultCenter.setOpaque(false);
    resultSouth = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 20));
    resultSouth.setOpaque(false);

    playAgainBtn.setPreferredSize(new Dimension(240, 80));
    playAgainBtn.setBackground(new Color(135, 17, 76));
    playAgainBtn.setForeground(Color.white);
    playAgainBtn.setBorder(BorderFactory.createLineBorder(Color.white, 6));
    playAgainBtn.setFont(new Font("Belta Regular", Font.BOLD, 40));
    playAgainBtn.addActionListener(new ButtonListener());

    scoresBtn.setPreferredSize(new Dimension(340, 80));
    scoresBtn.setBorder(BorderFactory.createLineBorder(Color.white, 6));
    scoresBtn.addActionListener(new ButtonListener());

    quitBtn.setPreferredSize(new Dimension(150, 80));
    quitBtn.setBorder(BorderFactory.createLineBorder(Color.white, 6));
    quitBtn.addActionListener(new ButtonListener());

    result = new JLabel();
    result.setFont(new Font("Belta Regular", Font.BOLD, 40));
    result.setForeground(Color.white);
    result.setBackground(new Color(0, 158, 121));
    result.setBorder(BorderFactory.createLineBorder(Color.white, 6));
    result.setOpaque(true);
    result.setPreferredSize(new Dimension(380, 80));

    winnersLabel = new JLabel();
    winnersLabel.setFont(new Font("Belta Regular", Font.BOLD, 40));
    winnersLabel.setForeground(Color.white);
    winnersLabel.setPreferredSize(new Dimension(420, 200));

    boardResultPanel.setLayout(new BorderLayout(50, 50));
    boardResultPanel.setPreferredSize(new Dimension(800, 700));
    boardResultPanel.setBackground(Color.yellow);
    boardResultPanel.add(resultNorth, BorderLayout.NORTH);
    boardResultPanel.add(resultCenter, BorderLayout.CENTER);
    boardResultPanel.add(resultSouth, BorderLayout.SOUTH);

    resultCenter.add(winnersLabel);
    resultSouth.add(scoresBtn);
    resultSouth.add(playAgainBtn);
    resultSouth.add(quitBtn);

    resultFrame.add(boardResultPanel);
  }
Esempio n. 12
0
  public GamePanel(String name, int l) {
    setFocusable(true);
    grabFocus();
    addMouseListener(this);
    addMouseMotionListener(this);
    addKeyListener(this);
    keys = new boolean[10000];

    try {
      scoreFont =
          Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(new File("BRLNSB.ttf")))
              .deriveFont(0, 32);
    } catch (IOException ioe) {
      System.out.println("error loading BRLNSB.tff");
    } catch (FontFormatException ffe) {
      System.out.println("Something went wrong with the font.");
    }

    gameBckgrnd = new ImageIcon("Backgroundimage.png").getImage();
    for (int i = 1; i < 7; i++) {
      magnetList.add(new ImageIcon("gamelayerstuff/powerups/magnet" + i + ".png").getImage());
    }

    coinPic = new ImageIcon("gamelayerstuff/coins/byellowcoin1.png").getImage();
    player1 = new Player(200, 300, 100, "sheldon");

    click = false;
    ground = true;
    pause = false;
    lvlClear = false;
    die = false;
    musicOn = true;

    player1.setVelo(150);
    player1.setInvi(true);
    // ------------------------------------------------------------------------------------------------------------------------------------
    // Sound
    coinSound = Applet.newAudioClip(getClass().getResource("coin_pickup_2.wav"));
    clicked = Applet.newAudioClip(getClass().getResource("menu_deselect.wav"));
    starSound = Applet.newAudioClip(getClass().getResource("star.wav"));
    bounce = Applet.newAudioClip(getClass().getResource("grav_step_4.wav"));
    bckGrndMusic = Applet.newAudioClip(getClass().getResource("bgmusic00.wav"));
    bckGrndMusic.loop();
    // ------------------------------------------------------------------------------------------------------------------------------------

    // distance=0;
    score = 0;
    coins = 0;
    level = 1;
    prevLvl = level;
    backy = 0;
    height = backy;
    dieHeight = 0;
    dieMenuHeight = 0;

    pauseB = new SButton(400, 670, "pause", "");
    resumeB = new SButton(100, 500, "resume", "");
    menuB = new SButton(100, 620, "back", "");
    muteB = new SButton(400, 600, "mute", "");
    unmuteB = new SButton(400, 600, "unmute", "");
    // System.out.println("characters/"+name+"/"+name+"35.png");
  }