From: peeweedee Date: Wed, 18 Dec 2013 13:03:54 +0000 (+0900) Subject: 新聞形式の描画速度向上施策 X-Git-Tag: REL-03.22.12b~4 X-Git-Url: http://git.osdn.net/view?p=tainavi%2FTinyBannavi.git;a=commitdiff_plain;h=ced3b269c222d4bb9abb8fc10d28e2fea836c022 新聞形式の描画速度向上施策 --- diff --git a/TinyBannavi/05_history.txt b/TinyBannavi/05_history.txt index 65a5fc0..297f019 100644 --- a/TinyBannavi/05_history.txt +++ b/TinyBannavi/05_history.txt @@ -10,9 +10,13 @@ 2chの番ナビスレ:http://toro.2ch.net/test/read.cgi/av/1352223253/ ★☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆★ -3.22.10β+1.5.12(2013-12-18) +3.22.12β+1.5.12(2013-12-XX) ■変更点 - ・(番組追跡) 処理の効率化 + ・(新聞形式)番組枠内テキストの描画を、LineBreakMeasurerからdrawGlyphVectorに変更。それに伴い番組詳細の描画行数制限を廃止 + +3.22.11β+1.5.12(2013-12-18) +■変更点 + ・(番組追跡)処理の効率化 ■バグ修正  ・(Web番組表[スカパー]) 1日の番組表が複数ページにまたがる場合に対応していない問題を修正(>>645.)  ・(ステータスビュー) りもこんと同じ修正(>>640.) diff --git a/TinyBannavi/src/tainavi/AbsPaperColorsDialog.java b/TinyBannavi/src/tainavi/AbsPaperColorsDialog.java index 307ed7c..0866a0a 100644 --- a/TinyBannavi/src/tainavi/AbsPaperColorsDialog.java +++ b/TinyBannavi/src/tainavi/AbsPaperColorsDialog.java @@ -139,7 +139,6 @@ abstract class AbsPaperColorsDialog extends JEscCancelDialog { private JCCLabel jLabel_titleFontColor = null; private JScrollPane jScrollPane_titleFontStyle = null; private JCheckBoxPanel jCBP_showDetail = null; - private JSliderPanel jSP_detailRows = null; private JComboBoxPanel jCBX_detailFont = null; private JSliderPanel jSP_detailFontSize = null; private JCCLabel jLabel_detailFontColor = null; @@ -286,7 +285,6 @@ abstract class AbsPaperColorsDialog extends JEscCancelDialog { to.setTitleFontColor(jLabel_titleFontColor.getChoosed()); to.setTitleFontStyle(getFontStyles((JNETable) jScrollPane_titleFontStyle.getViewport().getView())); to.setShowDetail(jCBP_showDetail.isSelected()); - to.setDetailRows(jSP_detailRows.getValue()); to.setDetailFont((String) jCBX_detailFont.getSelectedItem()); to.setDetailFontSize(jSP_detailFontSize.getValue()); to.setDetailFontColor(jLabel_detailFontColor.getChoosed()); @@ -586,9 +584,6 @@ abstract class AbsPaperColorsDialog extends JEscCancelDialog { CommonSwingUtils.putComponentOn(jPanel_fonts, jCBP_showDetail = new JCheckBoxPanel("表示する",LABEL_WIDTH), TITLE_WIDTH+ITEM_WIDTH, PARTS_HEIGHT, SEP_WIDTH, y); y += (PARTS_HEIGHT+SEP_HEIGHT_NARROW); - CommonSwingUtils.putComponentOn(jPanel_fonts, jSP_detailRows = new JSliderPanel("最大行数",LABEL_WIDTH,1,50,ITEM_WIDTH), TITLE_WIDTH+ITEM_WIDTH, PARTS_HEIGHT, SEP_WIDTH, y); - - y += (PARTS_HEIGHT+SEP_HEIGHT_NARROW); CommonSwingUtils.putComponentOn(jPanel_fonts, jCBX_detailFont = new JComboBoxPanel("フォント",LABEL_WIDTH,ITEM_WIDTH,true), LABEL_WIDTH+ITEM_WIDTH, PARTS_HEIGHT, SEP_WIDTH, y); y += (PARTS_HEIGHT+SEP_HEIGHT_NARROW); @@ -628,7 +623,6 @@ abstract class AbsPaperColorsDialog extends JEscCancelDialog { setFontStyles((JNETable) jScrollPane_titleFontStyle.getViewport().getView(), origenv.getTitleFontStyle()); // jCBP_showDetail.setSelected(origenv.getShowDetail()); - jSP_detailRows.setValue(origenv.getDetailRows()); if ( ! origenv.getDetailFont().equals("") ) { jCBX_detailFont.setSelectedItem(origenv.getDetailFont()); } diff --git a/TinyBannavi/src/tainavi/AbsPaperView.java b/TinyBannavi/src/tainavi/AbsPaperView.java index 0c76f79..6abc4b1 100644 --- a/TinyBannavi/src/tainavi/AbsPaperView.java +++ b/TinyBannavi/src/tainavi/AbsPaperView.java @@ -2512,7 +2512,6 @@ public abstract class AbsPaperView extends JPanel implements TickTimerListener,H JTXTButton.setSplitEpno(ec.getSplitEpno()); JTXTButton.setShowDetail(ec.getShowDetail()); JTXTButton.setDetailTab(ec.getDetailTab()); - JTXTButton.setDetailRows(ec.getDetailRows()); JTXTButton.setTitleFont(ec.getTitleFont()); JTXTButton.setTitleFontStyle(ec.getTitleFontStyle()); diff --git a/TinyBannavi/src/tainavi/JTXTButton.java b/TinyBannavi/src/tainavi/JTXTButton.java index 81f9f52..33bdadb 100644 --- a/TinyBannavi/src/tainavi/JTXTButton.java +++ b/TinyBannavi/src/tainavi/JTXTButton.java @@ -4,17 +4,20 @@ import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; +import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.font.FontRenderContext; -import java.awt.font.LineBreakMeasurer; +import java.awt.font.GlyphMetrics; +import java.awt.font.GlyphVector; import java.awt.font.TextAttribute; -import java.awt.font.TextLayout; +import java.awt.geom.Point2D; import java.awt.image.BufferedImage; -import java.text.AttributedCharacterIterator; -import java.text.AttributedString; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import javax.swing.JButton; import javax.swing.JLabel; @@ -32,8 +35,8 @@ public class JTXTButton extends JLabel { * フォントスタイル */ public static enum FontStyle { - BOLD ("太字"), - ITALIC ("斜体"), + BOLD ("太字"), + ITALIC ("斜体"), UNDERLINE ("下線"); private String name; @@ -85,24 +88,27 @@ public class JTXTButton extends JLabel { private static boolean splitEpno = false; private static boolean showDetail = true; private static float detailTab = 2.0F; - private static int detailRows = 3; private static Font defaultFont = new JLabel().getFont(); + private static Font titleFont = defaultFont; private static int titleFontSize = defaultFont.getSize(); private static Color titleFontColor = Color.BLUE; private static int titleFontStyle = Font.BOLD; - private static boolean titleFontUL = true; + private static Font detailFont = defaultFont; private static int detailFontSize = defaultFont.getSize(); private static Color detailFontColor = Color.DARK_GRAY; private static int detailFontStyle = defaultFont.getStyle(); - private static boolean detailFontUL = false; - private static Object aahint = RenderingHints.VALUE_TEXT_ANTIALIAS_ON; + + private static Font startFont = defaultFont; + + private static FontRenderContext frc = new FontRenderContext(null, RenderingHints.VALUE_TEXT_ANTIALIAS_ON, RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT); private static int columnWidth = 0; private static float heightMultiplier = 0; + /******************************************************************************* * コンストラクタ ******************************************************************************/ @@ -189,9 +195,6 @@ public class JTXTButton extends JLabel { public static void setDetailTab(float n) { detailTab = n; } - public static void setDetailRows(int n) { - detailRows = n; - } // フォントスタイル public static void setTitleFont(String fn) { @@ -216,6 +219,7 @@ public class JTXTButton extends JLabel { Font f = new Font(fn,detailFontStyle,detailFontSize); if ( f != null ) { detailFont = f; + startFont = f.deriveFont(Font.BOLD); return; } } @@ -224,6 +228,7 @@ public class JTXTButton extends JLabel { public static void setDetailFontSize(int n) { detailFontSize = n; detailFont = detailFont.deriveFont((float)detailFontSize); + startFont = startFont.deriveFont((float)detailFontSize); } public static void setDetailFontColor(Color c) { detailFontColor = c; @@ -231,40 +236,37 @@ public class JTXTButton extends JLabel { // フォントスタイルの変更 public static void setTitleFontStyle(ArrayList fsa) { - setTmpFontStyle(fsa); - titleFontStyle = tmpFontStyle; - titleFontUL = tmpFontUL; - titleFont = titleFont.deriveFont((titleFont.getStyle() & ~(Font.BOLD|Font.ITALIC)) | titleFontStyle); + titleFont = setFontStyle(titleFont, (float)titleFontSize, fsa); } public static void setDetailFontStyle(ArrayList fsa) { - setTmpFontStyle(fsa); - detailFontStyle = tmpFontStyle; - detailFontUL = tmpFontUL; - detailFont = detailFont.deriveFont((detailFont.getStyle() & ~(Font.BOLD|Font.ITALIC)) | detailFontStyle); + detailFont = setFontStyle(detailFont, (float)detailFontSize, fsa); } - private static void setTmpFontStyle(ArrayList fsa) { - tmpFontStyle = 0; - tmpFontUL = false; + + private static Font setFontStyle(Font f, float size, ArrayList fsa) { + Map attributes = new HashMap(); + attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR); + attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR); + attributes.remove(TextAttribute.UNDERLINE); for ( FontStyle fs : fsa ) { switch (fs) { case BOLD: - tmpFontStyle |= Font.BOLD; + attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); break; case ITALIC: - tmpFontStyle |= Font.ITALIC; + attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); break; case UNDERLINE: - tmpFontUL = true; + attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);//LOW_ONE_PIXEL); break; } } + attributes.put(TextAttribute.SIZE, size); + return f.deriveFont(attributes); } - private static int tmpFontStyle; - private static boolean tmpFontUL; // フォントエイリアスの変更 public static void setAAHint(Object o) { - aahint = o; + frc = new FontRenderContext(null, o, RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT); } @@ -289,12 +291,10 @@ public class JTXTButton extends JLabel { float draww = (float)imgw-DRAWTAB*2.0F; float drawh = (float)imgh; - float detailw = draww-detailTab; image = new BufferedImage(imgw, imgh, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D)image.createGraphics(); - g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,aahint); // アンチエイリアスの設定 g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); @@ -302,31 +302,41 @@ public class JTXTButton extends JLabel { // 開始時刻と延長警告の描画 if (showStart && tvd.start != null && tvd.start.length() > 0) { - // - Font fs = detailFont; - String sStr = tvd.start+" "+tvd.extension_mark; - // - Font f = fs.deriveFont(fs.getStyle() | Font.BOLD); - AttributedString as = new AttributedString(sStr); - as.addAttribute(TextAttribute.FONT, f); - as.addAttribute(TextAttribute.FOREGROUND, Color.BLACK, 0, 5); - if (sStr.length() > 6) { - as.addAttribute(TextAttribute.FOREGROUND, Color.RED, 6, sStr.length()); + FontMetrics fm = g2.getFontMetrics(startFont); + float hi = Float.valueOf(fm.getHeight()); + float as = Float.valueOf(fm.getAscent()); + + float startx = Float.valueOf(DRAWTAB); + float startw = draww; + float xposstartx = 0.0F; + + baseline = as; // 初期垂直位置 + + { + WrappedGlyphVector wgv = getWrappedGlyphVector(tvd.start, startw, xposstartx, startFont, as, frc); + GlyphVector gv = wgv.getGv(); + g2.setPaint(Color.BLACK); + g2.drawGlyphVector(gv, startx, baseline); + + xposstartx = wgv.getLastX(); // 後続有り + baseline += wgv.getLastY(); } - AttributedCharacterIterator ac = as.getIterator(); - FontRenderContext fc = g2.getFontRenderContext(); - LineBreakMeasurer m = new LineBreakMeasurer(ac,fc); - while ( m.getPosition() < sStr.length() ) { - TextLayout tl = m.nextLayout(draww); - baseline += tl.getAscent(); - tl.draw(g2, DRAWTAB, baseline); - baseline += tl.getDescent() + tl.getLeading(); + + { + WrappedGlyphVector wgv = getWrappedGlyphVector(" "+tvd.extension_mark, startw, xposstartx, startFont, as, frc); + GlyphVector gv = wgv.getGv(); + g2.setPaint(Color.RED); + g2.drawGlyphVector(gv, startx, baseline); + + baseline += wgv.getLastY(); } + + baseline += hi; } // タイトルの描画 String title = ( splitEpno ) ? tvd.splitted_title : tvd.title; - if (title.length() > 0) { + if ( title.length() > 0 ) { // String aMark; if (showStart && tvd.start.length() > 0) { @@ -340,28 +350,40 @@ public class JTXTButton extends JLabel { aMark = tvd.prefix_mark + tvd.newlast_mark; } } - String tStr = aMark+title+tvd.postfix_mark; - // - AttributedString as = new AttributedString(tStr); - as.addAttribute(TextAttribute.FONT, titleFont); - { - if (titleFontUL) { - as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL, aMark.length(), aMark.length()+title.length()); - } - as.addAttribute(TextAttribute.FOREGROUND, titleFontColor, aMark.length(), tStr.length()); - if (aMark.length() > 0) { - as.addAttribute(TextAttribute.FOREGROUND, Color.RED, 0, aMark.length()); - } + + FontMetrics fm = g2.getFontMetrics(titleFont); + float hi = Float.valueOf(fm.getHeight()); + float as = Float.valueOf(fm.getAscent()); + + float titlex = Float.valueOf(DRAWTAB); + float titlew = draww; + float xpos = 0.0F; + + if ( baseline == 0.0F ) { + baseline = as; // 初期垂直位置 } - AttributedCharacterIterator ac = as.getIterator(); - FontRenderContext fc = g2.getFontRenderContext(); - LineBreakMeasurer m = new LineBreakMeasurer(ac,fc); - while (m.getPosition() < tStr.length()) { - TextLayout tl = m.nextLayout(draww); - baseline += tl.getAscent(); - tl.draw(g2, DRAWTAB, baseline); - baseline += tl.getDescent() + tl.getLeading(); + + if ( aMark.length() > 0 ) { + WrappedGlyphVector wgv = getWrappedGlyphVector(aMark, titlew, xpos, titleFont, as, frc); + GlyphVector gv = wgv.getGv(); + g2.setPaint(Color.RED); + g2.drawGlyphVector(gv, titlex, baseline); + + xpos = wgv.getLastX(); // 後続有り + baseline += wgv.getLastY(); } + + { + WrappedGlyphVector wgv = getWrappedGlyphVector(title+tvd.postfix_mark, titlew, xpos, titleFont, as, frc); + GlyphVector gv = wgv.getGv(); + g2.setPaint(titleFontColor); + + drawString(g2, wgv, titlex, baseline); + + baseline += wgv.getLastY(); + } + + baseline += hi; } // 番組詳細の描画 @@ -373,27 +395,109 @@ public class JTXTButton extends JLabel { else { detail = tvd.detail; } - if ( detail.length() > 0 ) { - AttributedString as = new AttributedString(detail); - as.addAttribute(TextAttribute.FONT, detailFont); - if (detailFontUL) { - as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL); - } - as.addAttribute(TextAttribute.FOREGROUND, detailFontColor); - AttributedCharacterIterator ac = as.getIterator(); - FontRenderContext fc = g2.getFontRenderContext(); - LineBreakMeasurer m = new LineBreakMeasurer(ac,fc); - for ( int row=0; m.getPosition()0 && row linePositions = new ArrayList(); + public ArrayList getLinePositions() { return linePositions; } + public void addLinePosition(Rectangle r) { linePositions.add(r); } + } } diff --git a/TinyBannavi/src/tainavi/TraceProgram.java b/TinyBannavi/src/tainavi/TraceProgram.java index fa9e2ad..4d87678 100644 --- a/TinyBannavi/src/tainavi/TraceProgram.java +++ b/TinyBannavi/src/tainavi/TraceProgram.java @@ -107,8 +107,8 @@ public class TraceProgram { /** * 2つの文字を比較してスコアを計算する(special thanks to ◆kzz0PzTAMM) - * @param searchkey 番組追跡の検索キー - * @param target タイトル(中の文字がsearchkeyに何個含まれているかを確認する) + * @param searchkey 番組追跡の検索キーワード(「検索キーワード」の成分が「番組表のタイトルにどれくらい含まれているかを判定する」) + * @param target 番組表のタイトル * @return */ public static int sumScore(String searchkey, String target) @@ -134,7 +134,6 @@ public class TraceProgram { } else { if ( target.indexOf(searchkey) != -1 ) { - System.err.println("xxxx "+target+", "+searchkey); return 100; } }