Esempio n. 1
0
        public void DrawString(String str, int x, int y)
        {
            if (str == null || str.Equals(""))
            {
                return;
            }

            Font excelFont = font;

            if (font.Name.Equals("SansSerif"))
            {
                excelFont = new Font("Arial", (int)(font.Size / verticalPixelsPerPoint), font.Style);
            }
            else
            {
                excelFont = new Font(font.Name, (int)(font.Size / verticalPixelsPerPoint), font.Style);
            }
            FontDetails d      = StaticFontMetrics.GetFontDetails(excelFont);
            int         width  = (int)((d.GetStringWidth(str) * 8) + 12);
            int         height = (int)((font.Size / verticalPixelsPerPoint) + 6) * 2;

            y -= Convert.ToInt32((font.Size / verticalPixelsPerPoint) + 2 * verticalPixelsPerPoint);    // we want to Draw the shape from the top-left
            HSSFTextbox textbox = escherGroup.CreateTextbox(new HSSFChildAnchor(x, y, x + width, y + height));

            textbox.IsNoFill  = (true);
            textbox.LineStyle = (HSSFShape.LINESTYLE_NONE);
            HSSFRichTextString s        = new HSSFRichTextString(str);
            HSSFFont           hssfFont = MatchFont(excelFont);

            s.ApplyFont(hssfFont);
            textbox.String = (s);
        }
Esempio n. 2
0
 public void DrawString(String str, int x, int y)
 {
     if (string.IsNullOrEmpty(str))
     {
         return;
     }
     // TODO-Fonts: Fallback for missing font
     Font excelFont = new Font(SystemFonts.Get(font.Name.Equals("SansSerif") ? "Arial" : font.Name),
                               (int)(font.Size / verticalPixelsPerPoint), font.FontMetrics.Description.Style);
     {
         int width  = (int)((TextMeasurer.Measure(str, new TextOptions(excelFont)).Width * 8) + 12);
         int height = (int)((font.Size / verticalPixelsPerPoint) + 6) * 2;
         y -= Convert.ToInt32((font.Size / verticalPixelsPerPoint) + 2 * verticalPixelsPerPoint);    // we want to Draw the shape from the top-left
         HSSFTextbox textbox = escherGroup.CreateTextbox(new HSSFChildAnchor(x, y, x + width, y + height));
         textbox.IsNoFill  = (true);
         textbox.LineStyle = LineStyle.None;
         HSSFRichTextString s        = new HSSFRichTextString(str);
         HSSFFont           hssfFont = MatchFont(excelFont);
         s.ApplyFont(hssfFont);
         textbox.String = (s);
     }
 }