Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8203613

Problems on AlphaComposite option when printing using Java.awt.print package

    Details

    • Subcomponent:
      2d
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      ADDITIONAL SYSTEM INFORMATION :
      2D graphic & print related system / windows7 / 8 Update 171

      A DESCRIPTION OF THE PROBLEM :
      If you use Java.awt.AlphaComposite to apply an alpha value other than 1, the execution time will be greatly increased by repeatedly calling the print method 5 times more than when the alpha value is 1.
      In addition, when displaying a Korean character using the Tahoma font, if the alpha value is 1, the Korean character is displayed. But if the alpha value is not 1, Korean characters are broken.

      REGRESSION : Last worked in version 8u171

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      When set to [float alpha = 1.0f;], it takes approximately 7.303 seconds to print 10 pages each time the page prints out every page, and Korean characters are properly represented in the string.
      However, if you set [float alpha = 0.5f;], It takes 12.195 seconds to print a 10 page page by calling the print method 17 times for every page output. And Korean fonts displayed as boxes.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Korean fonts should not broken. and there should be no great time difference despite the float alpha value change.
      ACTUAL -
       if you set [float alpha = 0.5f;], It takes 12.195 seconds to print a 10 page page by calling the print method 17 times for every page output. And Korean fonts displayed as boxes (Broken Korean Fonts). - the total execution time is greatly prolonged than when I set the [float alpha =1.0f;]

      ---------- BEGIN SOURCE ----------
      @Override
      public int print(Graphics g, PageFormat pageFormat, int pageIndex)
      throws PrinterException {
      // TODO Auto-generated method stub
      int i;
      Graphics2D g2d;
      Line2D.Double line = new Line2D.Double();

      float alpha = 0.5f;

      //--- Validate the page number, we only print the first page ~ 10 Page
          if (pageIndex >= 0 && pageIndex <= 10) { //--- Create a graphic2D object a set the default parameters
           g2d = (Graphics2D) g;
          
      String _BmtLogTitle = "pageIndex[" + pageIndex + "]============= Call print.";
      System.out.println(_BmtLogTitle);
          
           Composite oldComp = g2d.getComposite();
          
           AlphaComposite ac = null;
          
           g2d.setColor(Color.black);

           //--- Translate the origin to be (0,0)
           g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

           //--- Print the vertical lines
           for (i = 0; i < pageFormat.getWidth(); i += INCH / 2) {

           ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
      g2d.setComposite(ac);

           line.setLine(i, 0, i, pageFormat.getHeight());
           g2d.draw(line);
          
           g2d.setComposite(oldComp);
           }

           //--- Print the horizontal lines
           for (i = 0; i < pageFormat.getHeight(); i += INCH / 2) {

           ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
      g2d.setComposite(ac);

           line.setLine(0, i, pageFormat.getWidth(), i);
           g2d.draw(line);
          
           g2d.setComposite(oldComp);
           }
          
           //license 그리기
      if(!this.licenseType.equals(""))
      {
      int _txStyle = fontStyleToInt("normal" ,"normal", "none");
      float _fontSize = 45;
      Color _txColor = Color.LIGHT_GRAY;
      mDefFont = new Font("tahoma", _txStyle, (int)_fontSize);

      g2d.setFont(mDefFont);
      g2d.setColor(_txColor);

      g2d.drawString(this.licenseType, 0, 0);
      FontMetrics metrics = g2d.getFontMetrics(mDefFont);
      g2d.drawString( this.licenseType, 0, metrics.getHeight() - metrics.getDescent());

      mDefFont = new Font("tahoma", _txStyle, 13);
      g2d.setFont(mDefFont);
      g2d.setColor(Color.black);

      g2d.drawString("Hello, 한글입력태스트!", 10, 150);
      }
        
           return (PAGE_EXISTS);
          }
          else
           return (NO_SUCH_PAGE);
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psadhukhan Prasanta Sadhukhan
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: