Example #1
0
        public override void DrawText(char[] str, int startAt, int len, Rectangle logicalTextBox, int textAlignment)
        {
#if DEBUG
            dbugCounter.dbugDrawStringCount++;
#endif
            var color = this.CurrentTextColor;
            if (color.A == 255)
            {
                var clipRect = Rectangle.Intersect(logicalTextBox,
                                                   new Rectangle(currentClipRect.Left,
                                                                 currentClipRect.Top,
                                                                 currentClipRect.Width,
                                                                 currentClipRect.Height));
                clipRect.Offset(canvasOriginX, canvasOriginY);
                MyWin32.SetRectRgn(hRgn,
                                   clipRect.Left,
                                   clipRect.Top,
                                   clipRect.Right,
                                   clipRect.Bottom);
                MyWin32.SelectClipRgn(tempDc, hRgn);

                unsafe
                {
                    fixed(char *startAddr = &str[0])
                    {
                        NativeTextWin32.TextOutUnsafe(tempDc,
                                                      (int)logicalTextBox.X + canvasOriginX,
                                                      (int)logicalTextBox.Y + canvasOriginY,
                                                      (startAddr + startAt), len);
                    }
                }
                MyWin32.SelectClipRgn(tempDc, IntPtr.Zero);

#if DEBUG
                //NativeTextWin32.dbugDrawTextOrigin(tempDc,
                //        logicalTextBox.X + canvasOriginX,
                //        logicalTextBox.Y + canvasOriginY);
#endif
            }
            else
            {
                //translucent / transparent text
                InitHdc();

                var intersectRect = Rectangle.Intersect(logicalTextBox,
                                                        new Rectangle(currentClipRect.Left,
                                                                      currentClipRect.Top,
                                                                      currentClipRect.Width,
                                                                      currentClipRect.Height));
                intersectRect.Offset(canvasOriginX, canvasOriginY);
                MyWin32.SetRectRgn(hRgn,
                                   intersectRect.Left,
                                   intersectRect.Top,
                                   intersectRect.Right,
                                   intersectRect.Bottom);
                MyWin32.SelectClipRgn(tempDc, hRgn);


                unsafe
                {
                    fixed(char *startAddr = &str[0])
                    {
                        NativeTextWin32.TextOutUnsafe(tempDc,
                                                      logicalTextBox.X + canvasOriginX,
                                                      logicalTextBox.Y + canvasOriginY,
                                                      (startAddr + startAt), len);
                    }
                }
#if DEBUG
                //NativeTextWin32.dbugDrawTextOrigin(tempDc,
                //    logicalTextBox.X + canvasOriginX,
                //    logicalTextBox.Y + canvasOriginY);
#endif
            }
        }
Example #2
0
        public override void DrawText(char[] str, int startAt, int len, Rectangle logicalTextBox, int textAlignment)
        {
            //this is the most common used function for text drawing
            //return;
#if DEBUG
            dbugDrawStringCount++;
#endif
            var color = this.CurrentTextColor;
            if (color.A == 255)
            {
                //1. find clip rect
                var clipRect = Rectangle.Intersect(logicalTextBox,
                                                   new Rectangle(currentClipRect.Left,
                                                                 currentClipRect.Top,
                                                                 currentClipRect.Width,
                                                                 currentClipRect.Height));
                //2. offset to canvas origin
                clipRect.Offset(canvasOriginX, canvasOriginY);
                //3. set rect rgn
                win32MemDc.SetClipRect(clipRect);

                unsafe
                {
                    fixed(char *startAddr = &str[0])
                    {
                        //4.
                        NativeTextWin32.TextOutUnsafe(originalHdc,
                                                      (int)logicalTextBox.X + canvasOriginX,
                                                      (int)logicalTextBox.Y + canvasOriginY,
                                                      (startAddr + startAt), len);
                    }
                }
                //5. clear rect rgn
                win32MemDc.ClearClipRect();
#if DEBUG
                //NativeTextWin32.dbugDrawTextOrigin(tempDc,
                //        logicalTextBox.X + canvasOriginX,
                //        logicalTextBox.Y + canvasOriginY);
#endif
            }
            else
            {
                //-------------------------------------------
                //not support translucent text in this version,
                //so=> draw opaque (like above)
                //-------------------------------------------
                //1. find clip rect
                var clipRect = Rectangle.Intersect(logicalTextBox,
                                                   new Rectangle(currentClipRect.Left,
                                                                 currentClipRect.Top,
                                                                 currentClipRect.Width,
                                                                 currentClipRect.Height));
                //2. offset to canvas origin
                clipRect.Offset(canvasOriginX, canvasOriginY);
                //3. set rect rgn
                win32MemDc.SetClipRect(clipRect);

                unsafe
                {
                    fixed(char *startAddr = &str[0])
                    {
                        //4.
                        NativeTextWin32.TextOutUnsafe(originalHdc,
                                                      (int)logicalTextBox.X + canvasOriginX,
                                                      (int)logicalTextBox.Y + canvasOriginY,
                                                      (startAddr + startAt), len);
                    }
                }
                //5. clear rect rgn
                win32MemDc.ClearClipRect();
#if DEBUG
                //NativeTextWin32.dbugDrawTextOrigin(tempDc,
                //        logicalTextBox.X + canvasOriginX,
                //        logicalTextBox.Y + canvasOriginY);
#endif
            }
        }