protected void BreakByWord(ref RepString repString, out RepString repStringLeftover, double rWidth) { FontProp fp = repString.fontProp; StringBuilder sb = new StringBuilder(); StringBuilder sbLeftover = new StringBuilder(); double r_X = 0; foreach (string s in repString.sText.Split(null)) { if (sb.Length > 0) { r_X += fp.rWidth(" "); } r_X += fp.rWidth(s); if (r_X <= rWidth) { if (sb.Length > 0) { sb.Append(" "); } sb.Append(s); } else { if (sbLeftover.Length > 0) { sbLeftover.Append(" "); } sbLeftover.Append(s); } } if (sbLeftover.Length > 0) { repStringLeftover = new RepString(repString.fontProp, sbLeftover.ToString()); } else { repStringLeftover = null; } if (sb.Length > 0) { repString = new RepString(repString.fontProp, sb.ToString()); } else { repString = null; } }
protected void BreakByLetter(ref RepString repString, out RepString repStringLeftover, double rWidth) { FontProp fp = repString.fontProp; StringBuilder sb = new StringBuilder(); StringBuilder sbLeftover = new StringBuilder(); double r_X = 0; foreach (char c in repString.sText) { r_X += fp.rWidth(Convert.ToString(c)); if (r_X <= rWidth) { sb.Append(c); } else { sbLeftover.Append(c); } } if (sbLeftover.Length > 0) { repStringLeftover = new RepString(repString.fontProp, sbLeftover.ToString()); } else { repStringLeftover = null; } if (sb.Length > 0) { repString = new RepString(repString.fontProp, sb.ToString()); } else { repString = null; } }
//----------------------------------------------------------------------------------------------------x /// <summary>Adds a report object to the current container at the current position.</summary> /// <param name="repObj">Report object to add to the container</param> public void Add(RepObj repObj) { if (status == Status.Init) { if (_container_Cur == null) { CreateNewContainer(); } } if (repObj is RepString) { RepString repString = (RepString)repObj; FontProp fp = repString.fontProp; String sText = repString.sText; Int32 iLineStartIndex = 0; Int32 iIndex = 0; while (true) { if (rY_Cur > container_Cur.rHeight) { _container_Cur = null; CreateNewContainer(); } Int32 iLineBreakIndex = 0; Double rPosX = rX_Cur; Double rLineBreakPos = 0; while (true) { if (iIndex >= sText.Length) { iLineBreakIndex = iIndex; rLineBreakPos = rPosX; break; } Char c = sText[iIndex]; rPosX += fp.rWidth(Convert.ToString(c)); if (rPosX >= container_Cur.rWidth) { if (iLineBreakIndex == 0) { if (iIndex == iLineStartIndex) // at least one character must be printed { iIndex++; } iLineBreakIndex = iIndex; break; } iIndex = iLineBreakIndex; break; } if (c == ' ') { iLineBreakIndex = iIndex + 1; rLineBreakPos = rPosX; } else if (c == '\n') { iLineBreakIndex = iIndex; iIndex++; break; } iIndex++; } if (iLineStartIndex == 0 && iIndex >= sText.Length) // add entire object { container_Cur.Add(rX_Cur, rY_Cur, repObj); rX_Cur = rLineBreakPos; break; } String sLine = sText.Substring(iLineStartIndex, iLineBreakIndex - iLineStartIndex); container_Cur.Add(rX_Cur, rY_Cur, new RepString(fp, sLine)); if (iIndex >= sText.Length) { rX_Cur = rLineBreakPos; break; } rX_Cur = 0; rY_Cur += fp.rLineFeed; iLineStartIndex = iIndex; } } else { Debug.Fail("Unknown object type"); container_Cur.Add(rX_Cur, rY_Cur, repObj); } }
//----------------------------------------------------------------------------------------------------x /// <summary>Adds a report object to the current container at the current position.</summary> /// <param name="al_RepObj">Result array for the report objects</param> /// <param name="repString">Report object to add to the container</param> /// <param name="rCurX"></param> /// <param name="rOfsX"></param> /// <param name="rAlignH">Horizontal allignment</param> /// <param name="rCurY"></param> /// <param name="rWidth"></param> internal void FormatString(ArrayList al_RepObj, RepString repString, ref Double rCurX, Double rOfsX, Double rAlignH, ref Double rCurY, Double rWidth) { FontProp fp = repString.fontProp; String sText = repString.sText; Int32 iLineStartIndex = 0; Int32 iIndex = 0; while (true) { Int32 iLineBreakIndex = 0; Double rPosX = rCurX; Double rLineBreakPos = 0; while (true) { if (iIndex >= sText.Length) { iLineBreakIndex = iIndex; rLineBreakPos = rPosX; break; } Char c = sText[iIndex]; if (c == '\r') { iLineBreakIndex = iIndex; iIndex++; c = sText[iIndex]; if (c == '\n') { iIndex++; } break; } rPosX += fp.rWidth(Convert.ToString(c)); if (rPosX >= rWidth) { if (iLineBreakIndex == 0 && rCurX <= rOfsX + 0.01) { if (iIndex == iLineStartIndex) // at least one character must be printed { iIndex++; } iLineBreakIndex = iIndex; break; } iIndex = iLineBreakIndex; break; } if (c == ' ') { iLineBreakIndex = iIndex + 1; rLineBreakPos = rPosX; } iIndex++; } if (iLineStartIndex == 0 && iIndex >= sText.Length) // add entire object { repString.matrixD.rDX = rCurX + (rWidth - rCurX) * rAlignH; repString.rAlignH = rAlignH; repString.matrixD.rDY = rCurY; repString.rAlignV = RepObj.rAlignBottom; al_RepObj.Add(repString); rCurX = rLineBreakPos; break; } if (iLineBreakIndex > iLineStartIndex && sText[iLineBreakIndex - 1] == ' ') { iLineBreakIndex--; } String sLine = sText.Substring(iLineStartIndex, iLineBreakIndex - iLineStartIndex); RepString rs = new RepString(fp, sLine); rs.matrixD.rDX = rCurX + (rWidth - rCurX) * rAlignH; rs.rAlignH = rAlignH; rs.matrixD.rDY = rCurY; rs.rAlignV = RepObj.rAlignBottom; al_RepObj.Add(rs); if (iIndex >= sText.Length) { rCurX = rLineBreakPos; break; } rCurX = rOfsX; rCurY += fp.rLineFeed; iLineStartIndex = iIndex; } }
//----------------------------------------------------------------------------------------------------x /// <summary>Adds a report object to the current container at the current position.</summary> /// <param name="repString">Report object to add to the container</param> /// <param name="container">Container</param> /// <param name="rCurX"></param> /// <param name="rOfsX"></param> /// <param name="rCurY"></param> /// <param name="rWidth"></param> public void PrintString(RepString repString, Container container, ref Double rCurX, Double rOfsX, ref Double rCurY, Double rWidth) { FontProp fp = repString.fontProp; String sText = repString.sText; Int32 iLineStartIndex = 0; Int32 iIndex = 0; while (true) { if (rCurY > container.rHeight) { NextContainer(); } Int32 iLineBreakIndex = 0; Double rPosX = rCurX; Double rLineBreakPos = 0; while (true) { if (iIndex >= sText.Length) { iLineBreakIndex = iIndex; rLineBreakPos = rPosX; break; } Char c = sText[iIndex]; rPosX += fp.rWidth(Convert.ToString(c)); if (rPosX >= rWidth) { if (iLineBreakIndex == 0) { if (iIndex == iLineStartIndex) // at least one character must be printed { iIndex++; } iLineBreakIndex = iIndex; break; } iIndex = iLineBreakIndex; break; } if (c == ' ') { iLineBreakIndex = iIndex + 1; rLineBreakPos = rPosX; } else if (c == '\n') { iLineBreakIndex = iIndex; iIndex++; break; } iIndex++; } if (iLineStartIndex == 0 && iIndex >= sText.Length) // add entire object { container.Add(rOfsX + rCurX, rCurY, repString); rCurX = rLineBreakPos; break; } String sLine = sText.Substring(iLineStartIndex, iLineBreakIndex - iLineStartIndex); container.Add(rOfsX + rCurX, rCurY, new RepString(fp, sLine)); if (iIndex >= sText.Length) { rCurX = rLineBreakPos; break; } rCurX = 0; rCurY += fp.rLineFeed; iLineStartIndex = iIndex; } }