Bug 46033

Summary: HSLF setFontSize in TableCell gets ignored
Product: POI Reporter: Fred Ross <fred>
Component: HSLFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: major    
Priority: P2    
Version: 3.5-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   

Description Fred Ross 2008-10-17 08:52:59 UTC
From the example on "How to create tables", when I run the example in either POI-3.2 or POI-3.5, the table ignores "setFontSize".

The PowerPoint generated has the table, but with a font size of 28.

     //table data              
      String[][] data = {
          {"INPUT FILE", "NUMBER OF RECORDS"},
          {"Item File", "11,559"},
          {"Vendor File", "300"},
          {"Purchase History File", "10,000"},
          {"Total # of requisitions", "10,200,038"}
      };

      SlideShow ppt = new SlideShow();

      Slide slide = ppt.createSlide();
      //create a table of 5 rows and 2 columns
      Table table = new Table(5, 2);
      for (int i = 0; i < data.length; i++) {
          for (int j = 0; j < data[i].length; j++) {
              TableCell cell = table.getCell(i, j);
              cell.setText(data[i][j]);

              RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
              rt.setFontName("Arial");
              rt.setFontSize(10);

              cell.setVerticalAlignment(TextBox.AnchorMiddle);
              cell.setHorizontalAlignment(TextBox.AlignCenter);
          }
      }

      //set table borders
      Line border = table.createBorder();
      border.setLineColor(Color.black);
      border.setLineWidth(1.0);
      table.setAllBorders(border);

      //set width of the 1st column
      table.setColumnWidth(0, 300);
      //set width of the 2nd column
      table.setColumnWidth(1, 150);

      slide.addShape(table);
      table.moveTo(100, 100);

      FileOutputStream out = new FileOutputStream("hslf-table.ppt");
      ppt.write(out);
      out.close();
Comment 1 Wayne Holder 2008-10-23 08:59:22 UTC
In addition to setFontSize() calls not working, calls to setFontName() and setBullet() also appear to have no effect.
Comment 2 Yegor Kozlov 2008-11-03 11:20:03 UTC
Fixed in r710134

Yegor
Comment 3 Wayne Holder 2010-06-15 14:18:27 UTC
I still see this issue in the 3.6 release, which I assume should contain the r710134 patches.  Or, has this not tricked through to a released version yet?
Comment 4 Wayne Holder 2010-06-15 16:27:55 UTC
I finally tracked down what was going on.  My test code was making a called to RichtextRun.setBullet(false) on the text run in the table.  This seems to disable the font settings.  The offending code is shown commented out below.

  TableCell cell = table.getCell(i, j);
  cell.setText(data[i][j]);
  RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
  rt.setFontName("Tahoma");
  rt.setFontSize(10);
  //rt.setBullet(false);
  cell.setVerticalAlignment(TextBox.AnchorMiddle);
  cell.setHorizontalAlignment(TextBox.AlignCenter);

I'm not sure if this is correct behavior, or not, but I can now workaround the issue.

Wayne