public static int GetCharOffsetByX(HCCanvas ACanvas, string AText, int X) { int Result = -1; if (X < 0) { Result = 0; } else if (X > ACanvas.TextWidth(AText)) { Result = AText.Length; } else { int vX = 0, vCharWidth = 0; for (int i = 1; i <= AText.Length; i++) { vCharWidth = ACanvas.TextWidth(AText[i - 1]); vX = vX + vCharWidth; if (vX > X) { if (vX - vCharWidth / 2 > X) { Result = i - 1; // 计为前一个后面 } else { Result = i; } break; } } } return(Result); }
protected void DoSectionPaintFooterAfter(object sender, int pageIndex, RECT rect, HCCanvas canvas, SectionPaintInfo paintInfo) { HCSection vSection = sender as HCSection; if (vSection.PageNoVisible) { int vSectionIndex = FSections.IndexOf(vSection); int vSectionStartPageIndex = 0; int vAllPageCount = 0; for (int i = 0; i <= FSections.Count - 1; i++) { if (i == vSectionIndex) { vSectionStartPageIndex = vAllPageCount; } vAllPageCount = vAllPageCount + FSections[i].PageCount; } string vS = string.Format(vSection.PageNoFormat, vSectionStartPageIndex + vSection.PageNoFrom + pageIndex, vAllPageCount); canvas.Brush.Style = HCBrushStyle.bsClear; canvas.Font.BeginUpdate(); try { canvas.Font.Size = 10; canvas.Font.Family = "宋体"; } finally { canvas.Font.EndUpdate(); } canvas.TextOut(rect.Left + (rect.Width - canvas.TextWidth(vS)) / 2, rect.Top + vSection.Footer.Height, vS); } }
public void PaintTo(HCCanvas canvas, RECT rect) { int vX = 0, vHeight = this.Height, vW = 0; HCCodeLineType vLineType = HCCodeLineType.White; if (this.FTextVisible) { vHeight -= 12; } RECT vRect = new RECT(); for (int i = 0, vLen = this.FCode.Length; i < vLen; i++) { vLineType = HCCodeLineType.White; this.OneBarProps(this.FCode[i], ref vW, ref vLineType); if (vLineType != HCCodeLineType.White) { canvas.Brush.Color = Color.Black; } else { canvas.Brush.Color = Color.White; } vRect.Left = vX; vRect.Top = 0; vRect.Right = vX + vW * this.FZoom; vRect.Bottom = vHeight; vX = vRect.Right; vRect.Offset(rect.Left, rect.Top); canvas.FillRect(vRect); } if (this.FCode == "") { canvas.Pen.BeginUpdate(); try { canvas.Pen.Width = 1; canvas.Pen.Color = Color.Black; } finally { canvas.Pen.EndUpdate(); } canvas.Rectangle(rect); } if (this.FTextVisible) { canvas.Font.BeginUpdate(); try { canvas.Font.Size = 8; canvas.Font.FontStyles.Value = 0; canvas.Font.Family = "Arial"; canvas.Font.Color = Color.Black; } finally { canvas.Font.EndUpdate(); } canvas.Brush.Style = HCBrushStyle.bsClear; if (this.FCode != "") { canvas.TextOut(rect.Left + (rect.Width - canvas.TextWidth(this.FText)) / 2, rect.Top + vHeight + 2, this.FText); } else { SIZE vSize = canvas.TextExtent("无效条码" + this.FText); canvas.TextOut(rect.Left + (rect.Width - vSize.cx) / 2, rect.Top + (rect.Height - vSize.cy) / 2, "无效条码" + this.FText); } } }