Example #1
0
        /// <summary>
        /// get the alignment for the current level (left, centered, right)
        /// </summary>
        /// <param name="columnNr"></param>
        /// <param name="level"></param>
        /// <param name="ADefault"></param>
        /// <returns></returns>
        protected eAlignment GetAlignment(Int32 columnNr, Int32 level, eAlignment ADefault)
        {
            eAlignment ReturnValue;
            TVariant   value;

            value       = FParameters.Get("ColumnAlign", columnNr, level);
            ReturnValue = ADefault;

            if (value.IsZeroOrNull())
            {
                ReturnValue = ADefault;
            }
            else if (value.ToString().CompareTo("left") == 0)
            {
                ReturnValue = eAlignment.eLeft;
            }
            else if (value.ToString().CompareTo("right") == 0)
            {
                ReturnValue = eAlignment.eRight;
            }
            else if (value.ToString().CompareTo("center") == 0)
            {
                ReturnValue = eAlignment.eCenter;
            }

            return(ReturnValue);
        }
Example #2
0
        private System.Drawing.StringFormat GetStringFormat(eAlignment AAlign)
        {
            System.Drawing.StringFormat ReturnValue;
            ReturnValue = FLeft;

            switch (AAlign)
            {
            case eAlignment.eDefault:
                ReturnValue = FLeft;
                break;

            case eAlignment.eLeft:
                ReturnValue = FLeft;
                break;

            case eAlignment.eRight:
                ReturnValue = FRight;
                break;

            case eAlignment.eCenter:
                ReturnValue = FCenter;
                break;
            }

            return(ReturnValue);
        }
Example #3
0
        /// <summary>
        /// Calculate the x position for a text, considering the width of the space and the width of the text, and the alignment
        /// </summary>
        protected float CalculateXPos(float AXPos, float AWidth, String ATxt, eAlignment AAlign)
        {
            // eDefault
            float XPos = Convert.ToInt32(AXPos);

            switch (AAlign)
            {
            case eAlignment.eCenter:
                XPos = Convert.ToInt32(AXPos) + (Convert.ToInt32(AWidth) - ATxt.Length) / 2;
                break;

            case eAlignment.eLeft:
                XPos = Convert.ToInt32(AXPos);
                break;

            case eAlignment.eRight:

                if (Convert.ToInt32(AWidth) > ATxt.Length)
                {
                    XPos = Convert.ToInt32(AXPos) + Convert.ToInt32(AWidth) - ATxt.Length;
                }
                else
                {
                    XPos = Convert.ToInt32(AXPos);
                }

                break;
            }

            return(XPos);
        }
Example #4
0
        private XStringFormat GetXStringFormat(eAlignment AAlign)
        {
            XStringFormat ReturnValue;

            ReturnValue = FXLeft;

            switch (AAlign)
            {
            case eAlignment.eDefault:
                ReturnValue = FXLeft;
                break;

            case eAlignment.eLeft:
                ReturnValue = FXLeft;
                break;

            case eAlignment.eRight:
                ReturnValue = FXRight;
                break;

            case eAlignment.eCenter:
                ReturnValue = FXCenter;
                break;
            }

            return(ReturnValue);
        }
Example #5
0
        /// <summary>
        /// prints into the current line, aligned x position
        ///
        /// </summary>
        public override Boolean PrintString(String ATxt, eFont AFont, eAlignment AAlign)
        {
            RectangleF rect = CalculatePrintStringRectangle(FLeftMargin, CurrentYPos, FWidth, AFont);

            if (PrintingMode == ePrintingMode.eDoPrint)
            {
                ATxt = GetFittedText(ATxt, AFont, rect.Width);
                FXGraphics.DrawString(ATxt, GetXFont(AFont), Brushes.Black, rect, GetXStringFormat(AAlign));
            }

            return((ATxt != null) && (ATxt.Length != 0));
        }
Example #6
0
        /// <summary>
        /// prints into the current line, aligned x position
        /// </summary>
        /// <returns>true if something was printed
        /// </returns>
        public override Boolean PrintString(String ATxt, eFont AFont, eAlignment AAlign)
        {
            Boolean ReturnValue;
            Int32   XPos;

            if ((ATxt == null) || (ATxt.Length == 0))
            {
                return(false);
            }

            ReturnValue = true;

            // eDefault
            XPos = 0;

            switch (AAlign)
            {
            case eAlignment.eCenter:

                if (FOrientation == eOrientation.ePortrait)
                {
                    XPos = (NumberOfCharactersPerLinePortrait - ATxt.Length) / 2;
                }
                else
                {
                    XPos = (NumberOfCharactersPerLineLandscape - ATxt.Length) / 2;
                }

                break;

            case eAlignment.eLeft:
                XPos = 0;
                break;

            case eAlignment.eRight:

                if (FOrientation == eOrientation.ePortrait)
                {
                    XPos = (Int16)(NumberOfCharactersPerLinePortrait - ATxt.Length);
                }
                else
                {
                    XPos = (Int16)(NumberOfCharactersPerLineLandscape - ATxt.Length);
                }

                break;
            }

            Print(XPos, Convert.ToInt32(CurrentYPos), ATxt);
            return(ReturnValue);
        }
Example #7
0
        /// <summary>
        /// prints into the current line, aligned x position
        ///
        /// </summary>
        public override Boolean PrintString(String ATxt, eFont AFont, eAlignment AAlign)
        {
            if ((ATxt == null) || (ATxt.Length == 0))
            {
                return(false);
            }

            UpdateBiggestLastUsedFont(AFont);

            RectangleF rect;

            rect = new RectangleF(FLeftMargin, CurrentYPos, FWidth, GetFont(AFont).GetHeight(FEv.Graphics) * CurrentLineHeight);

            if (PrintingMode == ePrintingMode.eDoPrint)
            {
                ATxt = GetFittedText(ATxt, AFont, rect.Width);
                FEv.Graphics.DrawString(ATxt, GetFont(AFont), Brushes.Black, rect, GetStringFormat(AAlign));
            }

            return(true);
        }
Example #8
0
        /// <summary>
        /// prints into the current line, absolute x position with width and alignment
        /// this method uses FCurrentXPos and FCurrentYPos to be able to continue a paragraph
        /// uses FCurrentXPos and FCurrentYPos to know where to start to print, and also sets
        /// valid values in those member variables
        /// </summary>
        /// <returns>true if any text was printed</returns>
        public override bool PrintStringWrap(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
        {
            int PreviousLength = -1;

            while (ATxt.Length > 0)
            {
                Int32 length = -1;

                PreviousLength = ATxt.Length;

                if (FPrinterBehaviour == ePrinterBehaviour.eFormLetter)
                {
                    length = GetTextLengthThatWillFit(ATxt, AFont, AXPos + AWidth - CurrentXPos);
                }
                else if (FPrinterBehaviour == ePrinterBehaviour.eReport)
                {
                    length = GetTextLengthThatWillFit(ATxt, AFont, AWidth);
                }

                if (FCurrentState.FNoWrap)
                {
                    length = ATxt.Length;
                }

                if (length > 0)
                {
                    string toPrint = ATxt.Substring(0, length);
                    ATxt = ATxt.Substring(length);

                    if (FPrinterBehaviour == ePrinterBehaviour.eFormLetter)
                    {
                        PrintString(toPrint, AFont, CurrentXPos, AWidth, AAlign);
                    }
                    else if (FPrinterBehaviour == ePrinterBehaviour.eReport)
                    {
                        PrintString(toPrint, AFont, AXPos, AWidth, AAlign);
                    }

                    CurrentXPos += GetWidthString(toPrint, AFont);

                    if (ATxt.Length > 0)
                    {
                        // there is still more to come, we need a new line
                        CurrentXPos = AXPos;
                        LineFeed(); // will use the biggest used font, and reset it
                    }
                }
                else if ((ATxt.Length > 0) && (CurrentXPos != AXPos))
                {
                    // the first word did not fit the space; needs a new line
                    CurrentXPos = AXPos;
                    LineFeed();
                }

                if (ATxt.Length == PreviousLength)
                {
                    TLogging.Log("No space for " + ATxt);
                    return false;
                }
            }

            if (FPrinterBehaviour == ePrinterBehaviour.eReport)
            {
                CurrentXPos = 0;
            }

            return true;
        }
Example #9
0
 /// <summary>
 /// This function uses the normal PrintString function to print into a given space.
 /// </summary>
 /// <returns>whether the text did fit that space or not.
 /// </returns>
 public override Boolean PrintStringAndFits(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
 {
     PrintString(ATxt, AFont, AXPos, AWidth, AAlign);
     return ATxt.Length <= AWidth;
 }
Example #10
0
        /// <summary>
        /// prints into the current line, absolute x position with width and alignment
        /// this method uses FCurrentXPos and FCurrentYPos to be able to continue a paragraph
        /// uses FCurrentXPos and FCurrentYPos to know where to start to print, and also sets
        /// valid values in those member variables
        /// </summary>
        /// <returns>s bool true if any text was printed</returns>
        public override bool PrintStringWrap(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
        {
            while (ATxt.Length > 0)
            {
                Int32 firstWordLength;
                Int32 length = GetTextLengthThatWillFit(ATxt, AFont, AWidth, out firstWordLength);

                if ((length <= 0) && (CurrentXPos == AXPos) && (firstWordLength > 0))
                {
                    // the word is too long, it will never fit;
                    // force to print the first word
                    // todo: this overwrites the text in the next cell; should we break the line inside the word, or not print the overlap?
                    // goal: the problem should be easy to notice by the user...
                    length = firstWordLength;
                    string toPrint = ATxt.Substring(0, length);
                    TLogging.Log("the text \"" + toPrint + "\" does not fit into the assigned space!");
                }

                if (length > 0)
                {
                    string toPrint = ATxt.Substring(0, length);
                    ATxt = ATxt.Substring(length);

                    float XPos = CalculateXPos(AXPos, AWidth, toPrint, AAlign);

                    //PrintString(toPrint, AFont, FCurrentXPos);
                    Print(Convert.ToInt32(XPos), Convert.ToInt32(CurrentYPos), toPrint);

                    //FCurrentXPos += GetWidthString(toPrint, AFont);

                    if (ATxt.Length > 0)
                    {
                        // there is still more to come, we need a new line
                        LineFeed(); // will use the biggest used font, and reset it
                    }
                }
                else if ((ATxt.Length > 0)
                         && (CurrentXPos != AXPos))
                {
                    // the first word did not fit the space; needs a new line
                    CurrentXPos = AXPos;
                    LineFeed();
                }
            }

            return true;
        }
Example #11
0
 /// <summary>
 /// prints into the current line, absolute x position with width and alignment
 /// this method uses FCurrentXPos and FCurrentYPos to be able to continue a paragraph
 /// uses FCurrentXPos and FCurrentYPos to know where to start to print, and also sets
 /// valid values in those member variables
 /// </summary>
 /// <returns>s bool true if any text was printed</returns>
 public virtual bool PrintStringWrap(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
 {
     return false;
 }
Example #12
0
        /// <summary>
        /// prints into the current line, absolute x position with width and alignment
        /// </summary>
        /// <returns>true if something was printed</returns>
        public override Boolean PrintString(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
        {
            if ((ATxt == null) || (ATxt.Length == 0))
            {
                return false;
            }

            UpdateBiggestLastUsedFont(AFont);

            RectangleF rect = new RectangleF(AXPos, CurrentYPos, AWidth, GetFont(AFont).GetHeight(FEv.Graphics) * CurrentLineHeight);

            if (PrintingMode == ePrintingMode.eDoPrint)
            {
                StringFormat f = GetStringFormat(AAlign);
                f.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;

                if (FPrinterBehaviour == ePrinterBehaviour.eReport)
                {
                    ATxt = GetFittedText(ATxt, AFont, rect.Width);
                }

                FEv.Graphics.DrawString(ATxt, GetFont(AFont), Brushes.Black, rect, f);
            }

            return true;
        }
Example #13
0
        /// <summary>
        /// prints into the current line, aligned x position
        ///
        /// </summary>
        public override Boolean PrintString(String ATxt, eFont AFont, eAlignment AAlign)
        {
            RectangleF rect = CalculatePrintStringRectangle(FLeftMargin, CurrentYPos, FWidth, AFont);

            if (PrintingMode == ePrintingMode.eDoPrint)
            {
                ATxt = GetFittedText(ATxt, AFont, rect.Width);
                FXGraphics.DrawString(ATxt, GetXFont(AFont), Brushes.Black, rect, GetXStringFormat(AAlign));
            }

            return (ATxt != null) && (ATxt.Length != 0);
        }
Example #14
0
        /// <summary>
        /// prints into the current line, absolute x position with width and alignment
        /// this method uses FCurrentXPos and FCurrentYPos to be able to continue a paragraph
        /// uses FCurrentXPos and FCurrentYPos to know where to start to print, and also sets
        /// valid values in those member variables
        /// </summary>
        /// <returns>true if any text was printed</returns>
        public override bool PrintStringWrap(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
        {
            int PreviousLength = -1;

            while (ATxt.Length > 0)
            {
                Int32 length = -1;

                PreviousLength = ATxt.Length;

                if (FPrinterBehaviour == ePrinterBehaviour.eFormLetter)
                {
                    length = GetTextLengthThatWillFit(ATxt, AFont, AXPos + AWidth - CurrentXPos);
                }
                else if (FPrinterBehaviour == ePrinterBehaviour.eReport)
                {
                    length = GetTextLengthThatWillFit(ATxt, AFont, AWidth);
                }

                if (FCurrentState.FNoWrap)
                {
                    length = ATxt.Length;
                }

                if (length > 0)
                {
                    string toPrint = ATxt.Substring(0, length);
                    ATxt = ATxt.Substring(length);

                    if (FPrinterBehaviour == ePrinterBehaviour.eFormLetter)
                    {
                        PrintString(toPrint, AFont, CurrentXPos, AWidth, AAlign);
                    }
                    else if (FPrinterBehaviour == ePrinterBehaviour.eReport)
                    {
                        PrintString(toPrint, AFont, AXPos, AWidth, AAlign);
                    }

                    CurrentXPos += GetWidthString(toPrint, AFont);

                    if (ATxt.Length > 0)
                    {
                        // there is still more to come, we need a new line
                        CurrentXPos = AXPos;
                        LineFeed(); // will use the biggest used font, and reset it
                    }
                }
                else if ((ATxt.Length > 0) && (CurrentXPos != AXPos))
                {
                    // the first word did not fit the space; needs a new line
                    CurrentXPos = AXPos;
                    LineFeed();
                }

                if (ATxt.Length == PreviousLength)
                {
                    TLogging.Log("No space for " + ATxt);
                    return(false);
                }
            }

            if (FPrinterBehaviour == ePrinterBehaviour.eReport)
            {
                CurrentXPos = 0;
            }

            return(true);
        }
Example #15
0
        /// <summary>
        /// get the alignment for the current level (left, centered, right)
        /// </summary>
        /// <param name="columnNr"></param>
        /// <param name="level"></param>
        /// <param name="ADefault"></param>
        /// <returns></returns>
        protected eAlignment GetAlignment(Int32 columnNr, Int32 level, eAlignment ADefault)
        {
            eAlignment ReturnValue;
            TVariant value;

            value = FParameters.Get("ColumnAlign", columnNr, level);
            ReturnValue = ADefault;

            if (value.IsZeroOrNull())
            {
                ReturnValue = ADefault;
            }
            else if (value.ToString().CompareTo("left") == 0)
            {
                ReturnValue = eAlignment.eLeft;
            }
            else if (value.ToString().CompareTo("right") == 0)
            {
                ReturnValue = eAlignment.eRight;
            }
            else if (value.ToString().CompareTo("center") == 0)
            {
                ReturnValue = eAlignment.eCenter;
            }

            return ReturnValue;
        }
Example #16
0
 /// <summary>
 /// prints into the current line, absolute x position with width and alignment
 /// this method uses FCurrentXPos and FCurrentYPos to be able to continue a paragraph
 /// uses FCurrentXPos and FCurrentYPos to know where to start to print, and also sets
 /// valid values in those member variables
 /// </summary>
 /// <returns>s bool true if any text was printed</returns>
 public virtual bool PrintStringWrap(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
 {
     return(false);
 }
Example #17
0
 /// <summary>
 /// This function uses the normal DrawString function to print into a given space.
 /// </summary>
 /// <returns>whether the text did fit that space or not.
 /// </returns>
 public abstract Boolean PrintStringAndFits(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign);
Example #18
0
 /// <summary>
 /// prints into the current line, absolute x position with width and alignment
 /// </summary>
 /// <returns>true if something was printed
 /// </returns>
 public abstract bool PrintString(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign);
Example #19
0
 /// <summary>
 /// prints into the current line, aligned x position
 /// </summary>
 /// <returns>true if something was printed
 /// </returns>
 public abstract Boolean PrintString(String ATxt, eFont AFont, eAlignment AAlign);
Example #20
0
 /// <summary>
 /// This function uses the normal DrawString function to print into a given space.
 /// </summary>
 /// <returns>whether the text did fit that space or not.
 /// </returns>
 public abstract Boolean PrintStringAndFits(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign);
Example #21
0
 /// <summary>
 /// prints into the current line, aligned x position
 ///
 /// </summary>
 public override Boolean PrintString(String ATxt, eFont AFont, eAlignment AAlign)
 {
     return(false);
 }
Example #22
0
        /// <summary>
        /// prints into the current line, absolute x position with width and alignment
        /// </summary>
        /// <returns>true if something was printed
        /// </returns>
        public override bool PrintString(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
        {
            String ToPrint;

            System.Int32 XPos;

            if ((ATxt == null) || (ATxt.Length == 0))
            {
                return(false);
            }

            ToPrint = GetFittedText(ATxt, AFont, AWidth);

            // eDefault
            XPos = Convert.ToInt32(AXPos);

            switch (AAlign)
            {
            case eAlignment.eCenter:
                XPos = Convert.ToInt32(AXPos) + (Convert.ToInt32(AWidth) - ToPrint.Length) / 2;
                break;

            case eAlignment.eLeft:
                XPos = Convert.ToInt32(AXPos);
                break;

            case eAlignment.eRight:

                if (Convert.ToInt32(AWidth) > ToPrint.Length)
                {
                    XPos = Convert.ToInt32(AXPos) + Convert.ToInt32(AWidth) - ToPrint.Length;
                }
                else
                {
                    XPos = Convert.ToInt32(AXPos);
                }

                break;
            }

            if (ToPrint.Length > Convert.ToInt32(AWidth))
            {
                ToPrint = ToPrint.Substring(0, Convert.ToInt32(AWidth));
            }

            Print(XPos, Convert.ToInt32(CurrentYPos), ToPrint);
            return(true);
        }
Example #23
0
 /// <summary>
 /// prints into the current line, absolute x position with width and alignment
 /// </summary>
 /// <returns>true if something was printed</returns>
 public override Boolean PrintString(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
 {
     return(false);
 }
Example #24
0
 /// <summary>
 /// This function uses the normal PrintString function to print into a given space.
 /// </summary>
 /// <returns>whether the text did fit that space or not.
 /// </returns>
 public override Boolean PrintStringAndFits(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
 {
     PrintString(ATxt, AFont, AXPos, AWidth, AAlign);
     return(ATxt.Length <= AWidth);
 }
Example #25
0
        private XStringFormat GetXStringFormat(eAlignment AAlign)
        {
            XStringFormat ReturnValue;

            ReturnValue = FXLeft;

            switch (AAlign)
            {
                case eAlignment.eDefault:
                    ReturnValue = FXLeft;
                    break;

                case eAlignment.eLeft:
                    ReturnValue = FXLeft;
                    break;

                case eAlignment.eRight:
                    ReturnValue = FXRight;
                    break;

                case eAlignment.eCenter:
                    ReturnValue = FXCenter;
                    break;
            }

            return ReturnValue;
        }
Example #26
0
 /// <summary>
 /// prints into the current line, aligned x position
 /// </summary>
 /// <returns>true if something was printed
 /// </returns>
 public abstract Boolean PrintString(String ATxt, eFont AFont, eAlignment AAlign);
Example #27
0
        /// <summary>
        /// prints into the current line, absolute x position with width and alignment
        /// </summary>
        /// <returns>true if something was printed</returns>
        public override Boolean PrintString(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
        {
            RectangleF rect = CalculatePrintStringRectangle(AXPos, CurrentYPos, AWidth, AFont);

            if (PrintingMode == ePrintingMode.eDoPrint)
            {
                if (FPrinterBehaviour == ePrinterBehaviour.eReport)
                {
                    ATxt = GetFittedText(ATxt, AFont, rect.Width);
                }

                if ((AAlign == eAlignment.eCenter) && Environment.OSVersion.ToString().StartsWith("Unix"))
                {
                    // it seems on Mono/Unix, the string aligning to the center does not work properly. so we do it manually
                    rect = new RectangleF(rect.Left + (AWidth - GetWidthString(ATxt, AFont)) / 2.0f, rect.Top, rect.Height, rect.Width);
                    FXGraphics.DrawString(ATxt, GetXFont(AFont), Brushes.Black, rect, GetXStringFormat(eAlignment.eLeft));
                }
                else
                {
                    XStringFormat f = GetXStringFormat(AAlign);
                    f.FormatFlags = XStringFormatFlags.MeasureTrailingSpaces;

                    //TLogging.Log("curr ypos " + CurrentYPos.ToString() + " " + AXPos.ToString() + " " + ATxt + AWidth.ToString());
                    FXGraphics.DrawString(ATxt, GetXFont(AFont), Brushes.Black, rect, f);
                }
            }

            return (ATxt != null) && (ATxt.Length != 0);
        }
Example #28
0
        /// <summary>
        /// prints into the current line, aligned x position
        ///
        /// </summary>
        public override Boolean PrintString(String ATxt, eFont AFont, eAlignment AAlign)
        {
            if ((ATxt == null) || (ATxt.Length == 0))
            {
                return false;
            }

            UpdateBiggestLastUsedFont(AFont);

            RectangleF rect;

            rect = new RectangleF(FLeftMargin, CurrentYPos, FWidth, GetFont(AFont).GetHeight(FEv.Graphics) * CurrentLineHeight);

            if (PrintingMode == ePrintingMode.eDoPrint)
            {
                ATxt = GetFittedText(ATxt, AFont, rect.Width);
                FEv.Graphics.DrawString(ATxt, GetFont(AFont), Brushes.Black, rect, GetStringFormat(AAlign));
            }

            return true;
        }
Example #29
0
        /// <summary>
        /// prints into the current line, absolute x position with width and alignment
        /// </summary>
        /// <returns>true if something was printed</returns>
        public override Boolean PrintString(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
        {
            if ((ATxt == null) || (ATxt.Length == 0))
            {
                return(false);
            }

            UpdateBiggestLastUsedFont(AFont);

            RectangleF rect = new RectangleF(AXPos, CurrentYPos, AWidth, GetFont(AFont).GetHeight(FEv.Graphics) * CurrentLineHeight);

            if (PrintingMode == ePrintingMode.eDoPrint)
            {
                StringFormat f = GetStringFormat(AAlign);
                f.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;

                if (FPrinterBehaviour == ePrinterBehaviour.eReport)
                {
                    ATxt = GetFittedText(ATxt, AFont, rect.Width);
                }

                FEv.Graphics.DrawString(ATxt, GetFont(AFont), Brushes.Black, rect, f);
            }

            return(true);
        }
Example #30
0
 /// <summary>
 /// prints into the current line, absolute x position with width and alignment
 /// </summary>
 /// <returns>true if something was printed
 /// </returns>
 public abstract bool PrintString(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign);
Example #31
0
        /// <summary>
        /// prints into the current line, absolute x position with width and alignment
        /// this method uses FCurrentXPos and FCurrentYPos to be able to continue a paragraph
        /// uses FCurrentXPos and FCurrentYPos to know where to start to print, and also sets
        /// valid values in those member variables
        /// </summary>
        /// <returns>s bool true if any text was printed</returns>
        public override bool PrintStringWrap(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
        {
            while (ATxt.Length > 0)
            {
                Int32 firstWordLength;
                Int32 length = GetTextLengthThatWillFit(ATxt, AFont, AWidth, out firstWordLength);

                if ((length <= 0) && (CurrentXPos == AXPos) && (firstWordLength > 0))
                {
                    // the word is too long, it will never fit;
                    // force to print the first word
                    // todo: this overwrites the text in the next cell; should we break the line inside the word, or not print the overlap?
                    // goal: the problem should be easy to notice by the user...
                    length = firstWordLength;
                    string toPrint = ATxt.Substring(0, length);
                    TLogging.Log("the text \"" + toPrint + "\" does not fit into the assigned space!");
                }

                if (length > 0)
                {
                    string toPrint = ATxt.Substring(0, length);
                    ATxt = ATxt.Substring(length);

                    float XPos = CalculateXPos(AXPos, AWidth, toPrint, AAlign);

                    //PrintString(toPrint, AFont, FCurrentXPos);
                    Print(Convert.ToInt32(XPos), Convert.ToInt32(CurrentYPos), toPrint);

                    //FCurrentXPos += GetWidthString(toPrint, AFont);

                    if (ATxt.Length > 0)
                    {
                        // there is still more to come, we need a new line
                        LineFeed(); // will use the biggest used font, and reset it
                    }
                }
                else if ((ATxt.Length > 0) &&
                         (CurrentXPos != AXPos))
                {
                    // the first word did not fit the space; needs a new line
                    CurrentXPos = AXPos;
                    LineFeed();
                }
            }

            return(true);
        }
Example #32
0
        /// <summary>
        /// Calculate the x position for a text, considering the width of the space and the width of the text, and the alignment
        /// </summary>
        protected float CalculateXPos(float AXPos, float AWidth, String ATxt, eAlignment AAlign)
        {
            // eDefault
            float XPos = Convert.ToInt32(AXPos);

            switch (AAlign)
            {
                case eAlignment.eCenter:
                    XPos = Convert.ToInt32(AXPos) + (Convert.ToInt32(AWidth) - ATxt.Length) / 2;
                    break;

                case eAlignment.eLeft:
                    XPos = Convert.ToInt32(AXPos);
                    break;

                case eAlignment.eRight:

                    if (Convert.ToInt32(AWidth) > ATxt.Length)
                    {
                        XPos = Convert.ToInt32(AXPos) + Convert.ToInt32(AWidth) - ATxt.Length;
                    }
                    else
                    {
                        XPos = Convert.ToInt32(AXPos);
                    }

                    break;
            }

            return XPos;
        }
Example #33
0
        /// <summary>
        /// prints into the current line, aligned x position
        /// </summary>
        /// <returns>true if something was printed
        /// </returns>
        public override Boolean PrintString(String ATxt, eFont AFont, eAlignment AAlign)
        {
            Boolean ReturnValue;
            Int32 XPos;

            if ((ATxt == null) || (ATxt.Length == 0))
            {
                return false;
            }

            ReturnValue = true;

            // eDefault
            XPos = 0;

            switch (AAlign)
            {
                case eAlignment.eCenter:

                    if (FOrientation == eOrientation.ePortrait)
                    {
                        XPos = (NumberOfCharactersPerLinePortrait - ATxt.Length) / 2;
                    }
                    else
                    {
                        XPos = (NumberOfCharactersPerLineLandscape - ATxt.Length) / 2;
                    }

                    break;

                case eAlignment.eLeft:
                    XPos = 0;
                    break;

                case eAlignment.eRight:

                    if (FOrientation == eOrientation.ePortrait)
                    {
                        XPos = (Int16)(NumberOfCharactersPerLinePortrait - ATxt.Length);
                    }
                    else
                    {
                        XPos = (Int16)(NumberOfCharactersPerLineLandscape - ATxt.Length);
                    }

                    break;
            }

            Print(XPos, Convert.ToInt32(CurrentYPos), ATxt);
            return ReturnValue;
        }
Example #34
0
        /// <summary>
        /// prints into the current line, absolute x position with width and alignment
        /// </summary>
        /// <returns>true if something was printed
        /// </returns>
        public override bool PrintString(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
        {
            String ToPrint;

            System.Int32 XPos;

            if ((ATxt == null) || (ATxt.Length == 0))
            {
                return false;
            }

            ToPrint = GetFittedText(ATxt, AFont, AWidth);

            // eDefault
            XPos = Convert.ToInt32(AXPos);

            switch (AAlign)
            {
                case eAlignment.eCenter:
                    XPos = Convert.ToInt32(AXPos) + (Convert.ToInt32(AWidth) - ToPrint.Length) / 2;
                    break;

                case eAlignment.eLeft:
                    XPos = Convert.ToInt32(AXPos);
                    break;

                case eAlignment.eRight:

                    if (Convert.ToInt32(AWidth) > ToPrint.Length)
                    {
                        XPos = Convert.ToInt32(AXPos) + Convert.ToInt32(AWidth) - ToPrint.Length;
                    }
                    else
                    {
                        XPos = Convert.ToInt32(AXPos);
                    }

                    break;
            }

            if (ToPrint.Length > Convert.ToInt32(AWidth))
            {
                ToPrint = ToPrint.Substring(0, Convert.ToInt32(AWidth));
            }

            Print(XPos, Convert.ToInt32(CurrentYPos), ToPrint);
            return true;
        }
Example #35
0
        /// <summary>
        /// prints into the current line, absolute x position with width and alignment
        /// </summary>
        /// <returns>true if something was printed</returns>
        public override Boolean PrintString(String ATxt, eFont AFont, float AXPos, float AWidth, eAlignment AAlign)
        {
            RectangleF rect = CalculatePrintStringRectangle(AXPos, CurrentYPos, AWidth, AFont);

            if (PrintingMode == ePrintingMode.eDoPrint)
            {
                if (FPrinterBehaviour == ePrinterBehaviour.eReport)
                {
                    ATxt = GetFittedText(ATxt, AFont, rect.Width);
                }

                if ((AAlign == eAlignment.eCenter) && Environment.OSVersion.ToString().StartsWith("Unix"))
                {
                    // it seems on Mono/Unix, the string aligning to the center does not work properly. so we do it manually
                    rect = new RectangleF(rect.Left + (AWidth - GetWidthString(ATxt, AFont)) / 2.0f, rect.Top, rect.Height, rect.Width);
                    FXGraphics.DrawString(ATxt, GetXFont(AFont), Brushes.Black, rect, GetXStringFormat(eAlignment.eLeft));
                }
                else
                {
                    XStringFormat f = GetXStringFormat(AAlign);
                    f.FormatFlags = XStringFormatFlags.MeasureTrailingSpaces;

                    //TLogging.Log("curr ypos " + CurrentYPos.ToString() + " " + AXPos.ToString() + " " + ATxt + AWidth.ToString());
                    FXGraphics.DrawString(ATxt, GetXFont(AFont), Brushes.Black, rect, f);
                }
            }

            return((ATxt != null) && (ATxt.Length != 0));
        }
Example #36
0
        private System.Drawing.StringFormat GetStringFormat(eAlignment AAlign)
        {
            System.Drawing.StringFormat ReturnValue;
            ReturnValue = FLeft;

            switch (AAlign)
            {
                case eAlignment.eDefault:
                    ReturnValue = FLeft;
                    break;

                case eAlignment.eLeft:
                    ReturnValue = FLeft;
                    break;

                case eAlignment.eRight:
                    ReturnValue = FRight;
                    break;

                case eAlignment.eCenter:
                    ReturnValue = FCenter;
                    break;
            }

            return ReturnValue;
        }