示例#1
0
 public static Dimension getScaledDimension(int width, int height) {
   if (FontUtils.getScale() == 1) {
     // dont need to scale
     return new Dimension(width, height);
   }
   return new Dimension(
       (int) (width * FontUtils.getScale()), (int) (height * FontUtils.getScale()));
 }
示例#2
0
 public static ImageIcon getScaledIcon(ImageIcon icon) {
   if (!isScaleImages()
       || icon == null
       || FontUtils.getScale() == 1
       || icon.getIconHeight() > STD_HEIGHT) {
     // dont need to scale
     return icon;
   }
   return new ImageIcon(
       ((ImageIcon) icon)
           .getImage()
           .getScaledInstance(
               (int) (icon.getIconWidth() * FontUtils.getScale()),
               (int) (icon.getIconHeight() * FontUtils.getScale()),
               Image.SCALE_SMOOTH));
 }
 protected void update() {
   ticks++;
   if (ticks % FPS == 0) {
     time++;
   }
   text = (int) (((float) getHourOfDay() / (float) ONE_DAY) * 100f) + "% of day " + getDay();
   textWidth = font.getTextWidth(text) + textPaddingX * 2f;
 }
示例#4
0
 public static Icon getScaledIcon(Icon icon) {
   if (!isScaleImages()
       || icon == null
       || FontUtils.getScale() == 1
       || !(icon instanceof ImageIcon)) {
     // dont need to scale (or cant)
     return icon;
   }
   return getScaledIcon((ImageIcon) icon);
 }
示例#5
0
  @Override
  public void setPlayers(PlayerInfo[] value) {
    // set header label indicating how many players are still needed
    String labelText = "";
    if (value.length == NUMBER_OF_PLAYERS) {
      labelText = "This game is ready to go!";
      addAiButton.setEnabled(false);
    } else {
      labelText = ("Waiting for Players: Need " + (NUMBER_OF_PLAYERS - value.length) + " more");
      addAiButton.setEnabled(true);
    }

    label.setText(labelText);

    // the center panel contains the individual player panels
    center.removeAll();

    // build an individual player panel and add it to the center panel
    for (int i = 0; i < value.length; i++) {
      String builtString = (i + 1) + " " + value[i].getName();
      JPanel playerPanel = new JPanel();
      playerPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // left justify the text in the panel
      playerPanel.setPreferredSize(new Dimension(200, 50));
      playerPanel.setBackground(
          value[i].getColor().getJavaColor()); // set the background color of the player
      JLabel playerLabel = new JLabel(builtString, SwingConstants.LEFT); // justify the text left
      FontUtils.setFont(playerLabel, LABEL_TEXT_SIZE);
      playerPanel.add(playerLabel);
      center.add(playerPanel);

      // add space between player panels
      Dimension minSize = new Dimension(5, 10);
      Dimension prefSize = new Dimension(5, 10);
      Dimension maxSize = new Dimension(Short.MAX_VALUE, 10);
      center.add(new Box.Filler(minSize, prefSize, maxSize));
    }
  }
示例#6
0
 public static int getScaledSize(int size) {
   return (int) (size * FontUtils.getScale());
 }
示例#7
0
  /**
   * Add a physical font's EmbedFontInfo object.
   *
   * @param fontUrl eg new java.net.URL("file:" + path)
   */
  public static void addPhysicalFont(String nameAsInFontTablePart, URL fontUrl) {

    // List<EmbedFontInfo> embedFontInfoList = fontInfoFinder.find(fontUrl, fontResolver,
    // fontCache);
    EmbedFontInfo[] embedFontInfoList = fontInfoFinder.find(fontUrl, fontResolver, fontCache);
    /* FOP r644208 (Bugzilla #44737) 3/04/08 made this an array,
    // so if you are using non-patched FOP, it needs to be at least this revision
    // (but doesn't seem to be in FOP 0.95 binary?!) */

    if (embedFontInfoList == null) {
      // Quite a few fonts exist that we can't seem to get
      // EmbedFontInfo for. To be investigated.
      log.warn(
          "Aborting: "
              + fontUrl.toString()
              + " (can't get EmbedFontInfo[] .. try deleting fop-fonts.cache?)");
      return;
    }

    StringBuffer debug = new StringBuffer();

    for (EmbedFontInfo fontInfo : embedFontInfoList) {

      /* EmbedFontInfo has:
      * - subFontName (if the underlying CustomFont is a TTC)
      * - PostScriptName = CustomFont.getFontName()
      * - FontTriplets named:
      * 		- CustomFont.getFullName() with quotes stripped
      * 		- CustomFont.getFontName() with whitespace stripped
      * 		- each family name        (with quotes stripped)
      *
      * By creating one PhysicalFont object
      * per triplet, each referring to the same
      * EmbedFontInfo, we increase the chances
      * of a match
      *
      ComicSansMS
      .. triplet Comic Sans MS (priority + 0
      .. triplet ComicSansMS (priority + 0

      ComicSansMS-Bold
      .. triplet Comic Sans MS Bold (priority + 0
      .. triplet ComicSansMS-Bold (priority + 0
      .. triplet Comic Sans MS (priority + 5
      *
      * but the second triplet is what FOP creates where its
      * getPostScriptName()
      * does FontUtil.stripWhiteSpace(getFullName());.
      *
      * and the third is just the family name.
      *
      * So we only get the first.
      *
      */

      if (fontInfo == null) {
        //				return;
        continue;
      }

      debug.append("------- \n");

      try {
        debug.append(fontInfo.getPostScriptName() + "\n");
        if (!fontInfo.isEmbeddable()) {
          //	        	log.info(tokens[x] + " is not embeddable; skipping.");

          /*
          * No point looking at this font, since if we tried to use it,
          * later, we'd get:
          *
          * com.lowagie.text.DocumentException: file:/usr/share/fonts/truetype/ttf-tamil-fonts/lohit_ta.ttf cannot be embedded due to licensing restrictions.
          at com.lowagie.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:364)
          at com.lowagie.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:335)
          at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:399)
          at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:345)
          at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:164)

          will be thrown if os_2.fsType == 2

          */
          log.warn(fontInfo.getEmbedFile() + " is not embeddable; ignoring this font.");

          // return;
          continue;
        }
      } catch (Exception e1) {
        // NB isEmbeddable() only exists in our patched FOP
        if (!loggedWarningAlready) {
          log.warn("Not using patched FOP; isEmbeddable() method missing.");
          loggedWarningAlready = true;
        }
      }

      PhysicalFont pf;

      //			for (Iterator iterIn = fontInfo.getFontTriplets().iterator() ; iterIn.hasNext();) {
      //				FontTriplet triplet = (FontTriplet)iterIn.next();

      FontTriplet triplet = (FontTriplet) fontInfo.getFontTriplets().get(0);
      // There is one triplet for each of the font family names
      // this font has, and we create a PhysicalFont object
      // for each of them.  For our purposes though, each of
      // these physical font objects contains the same info

      String lower = fontInfo.getEmbedFile().toLowerCase();
      log.debug("Processing physical font: " + lower);
      debug.append(
          ".. triplet " + triplet.getName() + " (priority " + triplet.getPriority() + "\n");

      pf = null;
      // xhtmlrenderer's org.xhtmlrenderer.pdf.ITextFontResolver.addFont
      // can handle
      // .otf, .ttf, .ttc, .pfb
      if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.endsWith(".ttc")) {
        pf = new PhysicalFont(triplet.getName(), fontInfo, fontResolver);
      } else if (lower.endsWith(".pfb")) {
        // See whether we have everything org.xhtmlrenderer.pdf.ITextFontResolver.addFont
        // will need - for a .pfb file, it needs a corresponding .afm or .pfm
        String afm = FontUtils.pathFromURL(lower);
        afm = afm.substring(0, afm.length() - 4) + ".afm"; // drop the 'file:'
        log.debug("Looking for: " + afm);
        File f = new File(afm);
        if (f.exists()) {

          log.debug(".. found");

          // Uncomment if you want to use the iText stuff in docx4j-extras
          //			        	// We're only interested if this font supports UTF-8 encoding
          //			        	// since otherwise iText can't use it (at least on a
          //			        	// UTF8 encoded XHTML document)
          //			        	try {
          //			    		    BaseFont bf = BaseFont.createFont(afm,
          //			    		    		BaseFont.IDENTITY_H,
          //									BaseFont.NOT_EMBEDDED);
          //						} catch (java.io.UnsupportedEncodingException uee) {
          //							log.error(afm + " does not support UTF encoding, so ignoring");
          //							continue;
          //						} catch (Exception e) {
          //							log.error(e.getMessage(), e);
          //							continue;
          //						}
          pf = new PhysicalFont(triplet.getName(), fontInfo, fontResolver);

        } else {
          // Should we be doing afm first, or pfm?
          String pfm = FontUtils.pathFromURL(lower);
          pfm = pfm.substring(0, pfm.length() - 4) + ".pfm"; // drop the 'file:'
          log.debug("Looking for: " + pfm);
          f = new File(pfm);
          if (f.exists()) {
            log.debug(".. found");

            // Uncomment if you want to use the iText stuff in docx4j-extras
            //				        	// We're only interested if this font supports UTF-8 encoding
            //				        	try {
            //				    		    BaseFont bf = BaseFont.createFont(pfm,
            //				    		    		BaseFont.IDENTITY_H,
            //										BaseFont.NOT_EMBEDDED);
            //							} catch (java.io.UnsupportedEncodingException uee) {
            //								log.error(pfm + " does not support UTF encoding, so ignoring");
            //								continue;
            //							} catch (Exception e) {
            //								log.error(e.getMessage(), e);
            //								continue;
            //							}
            pf = new PhysicalFont(triplet.getName(), fontInfo, fontResolver);
          } else {
            log.warn(
                "Skipping "
                    + triplet.getName()
                    + "; couldn't find .afm or .pfm for : "
                    + fontInfo.getEmbedFile());
          }
        }
      } else {
        log.warn(
            "Skipping " + triplet.getName() + "; unsupported type: " + fontInfo.getEmbedFile());
      }

      if (pf != null) {

        // Add it to the map
        physicalFontMap.put(pf.getName(), pf);
        log.debug("Added " + pf.getName() + " -> " + pf.getEmbeddedFile());

        if (nameAsInFontTablePart != null && !physicalFontMap.containsKey(nameAsInFontTablePart)) {
          physicalFontMap.put(nameAsInFontTablePart, pf);
          log.debug("Added '" + nameAsInFontTablePart + "' -> " + pf.getEmbeddedFile());
        }

        // We also need to add it to map by filename
        String filename = pf.getEmbeddedFile();
        filename = filename.substring(filename.lastIndexOf("/") + 1).toLowerCase();

        if (osName.startsWith("Mac")) {
          filename = filename.replace("%20", " ");
        }
        physicalFontMapByFilenameLowercase.put(filename, pf);
        log.debug("added to filename map: " + filename);

        //		        	String familyName = triplet.getName();
        //		        	pf.setFamilyName(familyName);
        //
        //		        	PhysicalFontFamily pff;
        //		        	if (physicalFontFamiliesMap.get(familyName)==null) {
        //		        		pff = new PhysicalFontFamily(familyName);
        //		        		physicalFontFamiliesMap.put(familyName, pff);
        //		        	} else {
        //		        		pff = physicalFontFamiliesMap.get(familyName);
        //		        	}
        //		        	pff.addFont(pf);

      }
    }

    log.debug(debug.toString());
  }
示例#8
0
  public PlayerWaitingView() {

    this.setOpaque(true);
    this.setLayout(new BorderLayout());
    this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH));

    // set the heading at the top of the pane
    label = new JLabel("Player Waiting View");
    FontUtils.setFont(label, LABEL_TEXT_SIZE);
    this.add(label, BorderLayout.NORTH);

    // create the center panel that displays player info
    center = new JPanel();
    center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
    this.add(center, BorderLayout.CENTER);

    // create the AI panel for the bottom of the pane
    aiPanel = new JPanel();
    aiPanel.setLayout(new BoxLayout(aiPanel, BoxLayout.Y_AXIS));

    // create the AI type panel
    JPanel aiTypePanel = new JPanel();
    aiTypePanel.setLayout(new BoxLayout(aiTypePanel, BoxLayout.X_AXIS));

    aiTypePanel.add(Box.createHorizontalGlue());

    JLabel aiTypeLabel = new JLabel("Select AI Type:");
    FontUtils.setFont(aiTypeLabel, AI_TEXT_SIZE);
    aiTypePanel.add(aiTypeLabel);

    aiTypePanel.add(Box.createRigidArea(new Dimension(5, 0)));

    aiModel = new SpinnerListModel();
    aiChoices = new JSpinner(aiModel);
    ((JSpinner.DefaultEditor) aiChoices.getEditor()).getTextField().setEditable(false);
    FontUtils.setFont(aiChoices, AI_TEXT_SIZE);
    aiTypePanel.add(aiChoices);

    aiTypePanel.add(Box.createHorizontalGlue());

    aiPanel.add(aiTypePanel);

    aiPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // create the AI button panel
    JPanel aiButtonPanel = new JPanel();
    aiButtonPanel.setLayout(new BoxLayout(aiButtonPanel, BoxLayout.X_AXIS));

    aiButtonPanel.add(Box.createHorizontalGlue());

    addAiButton = new JButton("Add a computer player");
    addAiButton.addActionListener(actionListener);
    FontUtils.setFont(addAiButton, BUTTON_TEXT_SIZE);
    aiButtonPanel.add(addAiButton);

    aiButtonPanel.add(Box.createHorizontalGlue());

    aiPanel.add(aiButtonPanel);

    aiPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // add the AI panel
    this.add(aiPanel, BorderLayout.SOUTH);
  }
 public void render(ShapeRenderer uiShapeRenderer, float x, float y) {
   font.drawWhiteFont(text, x, y, true);
 }