/* * Created on Mar 2, 2022 by nick * */ package jmsltestsuite; import java.awt.Dimension; import java.awt.Font; import java.awt.FontFormatException; import java.awt.Graphics; import java.awt.Graphics2D; import java.io.File; import java.io.IOException; import javax.swing.JFrame; import javax.swing.JPanel; import com.softsynth.jmsl.score.Score; public class SMuFLOpenTypeTest extends JPanel { Font musicFont; Font textFont = new Font("Serif", Font.PLAIN, 24); public void paintComponent(Graphics g) { super.paintComponent(g); System.out.println("paint"); Graphics2D g2d = (Graphics2D) g; Score.setupAntiAliasedGraphics(g2d); if (musicFont != null) { g2d.setFont(musicFont); } g2d.drawString("\uE52A", 10, 60); g2d.drawString("\uE050", 100, 60); g2d.drawString("\ue0a4", 10, 120); g2d.drawString("\uE4E5", 100, 120); // g2d.drawString("\uE210", 40, 170); g2d.drawString("\uE042", 40, 170); g2d.setFont(textFont); g2d.drawString(musicFont != null ? musicFont.getFontName() : "Some text", 150, 150); } void dolayout() { setPreferredSize(new Dimension(400, 200)); } void make() throws FontFormatException, IOException { File smuflDir = new File("C:/PROGRAMS_VOLUME/jwork/SMuFL"); // Font f = Font.createFont(Font.TRUETYPE_FONT, new File(smuflDir, "Petaluma.otf")); // Font f = Font.createFont(Font.TRUETYPE_FONT, new File(smuflDir, "Bravura.otf")); Font f = Font.createFont(Font.TRUETYPE_FONT, new File(smuflDir, "Leland.otf")); musicFont = f.deriveFont(Font.TRUETYPE_FONT, 48); System.out.println(musicFont.getFontName()); } public static void main(String[] args) { JFrame jf = new JFrame("OpenType music font test"); try { Score.setAntiAliasingHints(true); SMuFLOpenTypeTest test = new SMuFLOpenTypeTest(); test.dolayout(); test.make(); jf.add(test); jf.pack(); } catch (FontFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } jf.setVisible(true); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }