コード例 #1
0
 /// <summary>
 /// 没有任何显示格式限制下的打印
 /// </summary>
 /// <param name="g"></param>
 /// <param name="propertySystem"></param>
 private static void _drawNoFormat(Graphics g, AojPrintPropertySystem propertySystem)
 {
     StringFormat sf = GetStringFormatAlignment(propertySystem);
     g.DrawString(propertySystem.Value, propertySystem.GetFont(), GetBrush(propertySystem.FontColor)
         , propertySystem.RealX, propertySystem.RealY, sf);
 }
コード例 #2
0
 /// <summary>
 /// 绘画文本,如果有特殊的处理如转换格式等均在此处做转换处理后输出
 /// </summary>
 /// <param name="g">画板</param>
 /// <param name="propertySystem">属性</param>
 public static void DrawString(Graphics g, AojPrintPropertySystem propertySystem)
 {
     //文本为空时,不进行打印
     if (string.IsNullOrEmpty(propertySystem.Value))
     {
         return;
     }
     //检查打印的字符串是否需要进行格式转换
     if (propertySystem.ViewFormat != 0)
     {
         _formatString(propertySystem);
     }
     //如果Font不为空时进行打印
     if (propertySystem.GetFont() != null)
     {
         //读取字体的显示模式
         FontDisplayFormat fontDisplayFormat= AojUnitConvert.GetEnumType<FontDisplayFormat,string>(propertySystem.FontDisplayFormat);
         switch (fontDisplayFormat)
         {
             case FontDisplayFormat.NoFormat:
                 _drawNoFormat(g,propertySystem);
                 break;
             case FontDisplayFormat.AutoSize:
                 _drawAutoSize(g, propertySystem);
                 break;
             case FontDisplayFormat.AutoFormat:
             default:
                 break;
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// 自适应区域宽高度进行打印
 /// </summary>
 /// <param name="g">图像区域</param>
 /// <param name="propertySystem"></param>
 private static void _drawAutoSize(Graphics g, AojPrintPropertySystem propertySystem)
 {
     Font _currentFont = propertySystem.GetFont();
     while (true)
     {
         SizeF size = g.MeasureString(propertySystem.Value, _currentFont);
         //如果算出来的大小均在指定的范围内则跳出循环,打印出来
         if ((size.Width < propertySystem.Width) && (size.Height < propertySystem.Height))
         {
             break;
         }
         if (_currentFont.Size - 0.1f < 0)
         {
             //Throw Exception
             _currentFont = null;
             break;
         }
         _currentFont = new Font(_currentFont.FontFamily, _currentFont.Size - 0.1f, _currentFont.Style);
     }
     if (_currentFont != null)
     {
         StringFormat sf = GetStringFormatAlignment(propertySystem);
         g.DrawString(propertySystem.Value, _currentFont, GetBrush(propertySystem.FontColor)
         , propertySystem.RealX, propertySystem.RealY, sf);
     }
 }