MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / printString

Method printString

ij/src/main/java/ij/plugin/frame/Editor.java:740–793  ·  view source on GitHub ↗
(PrintJob pjob, Graphics pg, String s)

Source from the content-addressed store, hash-verified

738 }
739
740 void printString (PrintJob pjob, Graphics pg, String s) {
741 int pageNum = 1;
742 int linesForThisPage = 0;
743 int linesForThisJob = 0;
744 int topMargin = 30;
745 int leftMargin = 30;
746 int bottomMargin = 30;
747
748 if (!(pg instanceof PrintGraphics))
749 throw new IllegalArgumentException ("Graphics contextt not PrintGraphics");
750 if (IJ.isMacintosh()) {
751 topMargin = 0;
752 leftMargin = 0;
753 bottomMargin = 0;
754 }
755 StringReader sr = new StringReader (s);
756 LineNumberReader lnr = new LineNumberReader (sr);
757 String nextLine;
758 int pageHeight = pjob.getPageDimension().height - bottomMargin;
759 Font helv = new Font(getFontName(), Font.PLAIN, 10);
760 pg.setFont (helv);
761 FontMetrics fm = pg.getFontMetrics(helv);
762 int fontHeight = fm.getHeight();
763 int fontDescent = fm.getDescent();
764 int curHeight = topMargin;
765 try {
766 do {
767 nextLine = lnr.readLine();
768 if (nextLine != null) {
769 nextLine = detabLine(nextLine);
770 if ((curHeight + fontHeight) > pageHeight) {
771 // New Page
772 pageNum++;
773 linesForThisPage = 0;
774 pg.dispose();
775 pg = pjob.getGraphics();
776 if (pg != null)
777 pg.setFont (helv);
778 curHeight = topMargin;
779 }
780 curHeight += fontHeight;
781 if (pg != null) {
782 pg.drawString (nextLine, leftMargin, curHeight - fontDescent);
783 linesForThisPage++;
784 linesForThisJob++;
785 }
786 }
787 } while (nextLine != null);
788 } catch (EOFException eof) {
789 // Fine, ignore
790 } catch (Throwable t) { // Anything else
791 IJ.handleException(t);
792 }
793 }
794
795 String detabLine(String s) {
796 if (s.indexOf('\t')<0)

Callers 1

printMethod · 0.95

Calls 11

isMacintoshMethod · 0.95
getFontNameMethod · 0.95
detabLineMethod · 0.95
handleExceptionMethod · 0.95
getGraphicsMethod · 0.80
setFontMethod · 0.65
getFontMetricsMethod · 0.45
getHeightMethod · 0.45
readLineMethod · 0.45
disposeMethod · 0.45
drawStringMethod · 0.45

Tested by

no test coverage detected