Beispiel #1
0
        /// <summary>
        /// Align chunks verticaly
        /// </summary>
        /// <param name="align"></param>
        public void VertAlign(VertAlign align)
        {
            switch (align)
            {
            case Core.VertAlign.Top:
                for (int i = 0; i < list.Count; i++)
                {
                    var chunk = list[i];
                    chunk.Rect.Y = Y;
                }
                break;

            case Core.VertAlign.Middle:
                for (int i = 0; i < list.Count; i++)
                {
                    var chunk = list[i];
                    chunk.Rect.Y = Y + Height / 2 - chunk.Rect.Height / 2;
                }
                break;

            case Core.VertAlign.Bottom:
                for (int i = 0; i < list.Count; i++)
                {
                    var chunk = list[i];
                    chunk.Rect.Y = Y + Height - chunk.Rect.Height;
                }
                break;
            }
        }
Beispiel #2
0
 private void HTMLAlign(StringBuilder sb, HorzAlign horzAlign, VertAlign vertAlign)
 {
     sb.Append("text-align:");
     if (horzAlign == HorzAlign.Left)
     {
         sb.Append("Left");
     }
     else if (horzAlign == HorzAlign.Right)
     {
         sb.Append("Right");
     }
     else if (horzAlign == HorzAlign.Center)
     {
         sb.Append("Center");
     }
     else if (horzAlign == HorzAlign.Justify)
     {
         sb.Append("Justify");
     }
     sb.Append(";vertical-align:");
     if (vertAlign == VertAlign.Top)
     {
         sb.Append("Top");
     }
     else if (vertAlign == VertAlign.Bottom)
     {
         sb.Append("Bottom");
     }
     else if (vertAlign == VertAlign.Center)
     {
         sb.Append("Middle");
     }
     sb.Append(";word-wrap:break-word");
     sb.Append(";");
 }
 internal void Compile(IEnumerator<HtmlChunk> source, int width, TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
 {
     this.d.Clear();
     this.CompiledWidth = width;
     this.d.Parse(source, width, align, valign);
     this.UpdateHeight();
 }
Beispiel #4
0
 internal void FinishLine(DeviceChunkLine line, TextAlign align, VertAlign valign)
 {
     if (line != null)
     {
         line.HorzAlign(align);
         line.VertAlign(valign);
     }
 }
Beispiel #5
0
 internal void Compile(IEnumerator<HtmlChunk> source, int width, string id = null, HtFont font = null, HtColor color = default(HtColor), TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
 {
     this.d.Clear();
     this.CompiledWidth = width;
     this.d.Parse(source, width, id, font, color, align, valign);
     this.MergeSameTextChunks();
     this.UpdateHeight();
     //this.UpdateWidth();
 }
Beispiel #6
0
 /// <summary>
 /// Sets the vertical text alignment for tthe selected objects.
 /// </summary>
 /// <param name="align">Alignment to set.</param>
 public void SetVAlign(VertAlign align)
 {
     foreach (TextObject text in ModifyList)
     {
         text.VertAlign = align;
     }
     FDesigner.LastFormatting.VertAlign = align;
     FDesigner.SetModified();
 }
Beispiel #7
0
        private string GetRTFVAlignment(VertAlign VAlign)
        {
            switch (VAlign)
            {
            case VertAlign.Top:
                return("\\clvertalt");

            case VertAlign.Center:
                return("\\clvertalc");

            default:
                return("\\clvertalb");
            }
        }
Beispiel #8
0
 private void HTMLAlign(FastString sb, HorzAlign horzAlign, VertAlign vertAlign, bool wordWrap)
 {
     sb.Append("text-align:");
     if (horzAlign == HorzAlign.Left)
     {
         sb.Append("Left");
     }
     else if (horzAlign == HorzAlign.Right)
     {
         sb.Append("Right");
     }
     else if (horzAlign == HorzAlign.Center)
     {
         sb.Append("Center");
     }
     else if (horzAlign == HorzAlign.Justify)
     {
         sb.Append("Justify");
     }
     sb.Append(";vertical-align:");
     if (vertAlign == VertAlign.Top)
     {
         sb.Append("Top");
     }
     else if (vertAlign == VertAlign.Bottom)
     {
         sb.Append("Bottom");
     }
     else if (vertAlign == VertAlign.Center)
     {
         sb.Append("Middle");
     }
     if (wordWrap)
     {
         sb.Append(";word-wrap:break-word");
     }
     sb.Append(";overflow:hidden;");
 }
Beispiel #9
0
        /// <summary>
        /// Aligns prev line, creates new line and applies Y to it
        /// </summary>
        /// <param name="prevLine">previous line</param>
        /// <param name="viewPortWidth">viewport width</param>
        /// <param name="prevAlign">text align</param>
        /// <param name="prevVAlign">vertical align</param>
        /// <returns>new empty line</returns>
        internal DeviceChunkLine NewLine(DeviceChunkLine prevLine, int viewPortWidth, TextAlign prevAlign, VertAlign prevVAlign)
        {
            int freeY = 0;

            if (prevLine != null)
            {
                this.FinishLine(prevLine, prevAlign, prevVAlign);
                freeY = prevLine.Y + prevLine.Height;
            }
            var newLine = OP <DeviceChunkLine> .Acquire();

            newLine.MaxWidth = viewPortWidth;
            newLine.Y        = freeY;
            this.list.Add(newLine);
            return(newLine);
        }
Beispiel #10
0
 public void Parse(IEnumerator<HtmlChunk> source, int width, string id = null, HtFont font = null, HtColor color = default(HtColor), TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
 {
     compiled.Compile(source, width, id, font, color, align, valign);
     offsetApplied = false;
 }
Beispiel #11
0
 private void HTMLGetStyle(StringBuilder style, Font Font, Color TextColor, Color FillColor, HorzAlign HAlign, VertAlign VAlign,
                           Border Border, System.Windows.Forms.Padding Padding, bool RTL)
 {
     HTMLFontStyle(style, Font);
     style.Append("color:").Append(ExportUtils.HTMLColor(TextColor)).Append(";");
     style.Append("background-color:");
     style.Append(FillColor == Color.Transparent ? "transparent" : ExportUtils.HTMLColor(FillColor)).Append(";");
     HTMLAlign(style, HAlign, VAlign);
     HTMLBorder(style, Border);
     HTMLPadding(style, Padding);
     HTMLRtl(style, RTL);
     style.AppendLine("}");
 }
Beispiel #12
0
        public void Draw(Graphics gfx, Font font, Brush textBrush, int fixedH, VertAlign align, ref int left, ref int h)
        {
            left += LeftMargin;
            this.Left = left;
            int y = TopMargin;

            if (fixedH == 0)
                fixedH = h;

            switch (Vis)
            {
                case "Text":
                    string output;
                    if (OnlyValue)
                        output = CurrDataValue.ToString();
                    else
                        output = Prefix + CurrDataValue.ToString() + Postfix;

                    SizeF txtSize = gfx.MeasureString(output, font);
                    y += setAlignment(align, (int)txtSize.Height, fixedH);

                    gfx.DrawString(output, font, textBrush, left, y);

                    left += (int)txtSize.Width;
                    this.H = (int)txtSize.Height;
                    h = Math.Max(h, this.H);
                    break;
                case "Spinner":
                    if (!(spinnerImg == null || prevDraw.Ticks == 0 || Min == Max))
                    {
                        float speed = interpolateData(CurrDataValue, MinSpin, MaxSpin);
                        double s = DateTime.Now.Subtract(prevDraw).TotalSeconds; //seconds elapsed since last draw
                        int destW = zoomLength(spinnerImg.Width, Zoom);
                        int destH = zoomLength(spinnerImg.Height, Zoom);

                        //left += spinMargin - destW / 2;

                        spin += speed * s;

                        y += setAlignment(align, destH, fixedH);

                        gfx.TranslateTransform(left + destW / 2, y + destH / 2);
                        gfx.RotateTransform((float)spin);
                        gfx.TranslateTransform(-destW / 2, -destH / 2);

                        gfx.DrawImage(spinnerImg, 0, 0, destW, destH);
                        gfx.ResetTransform();

                        left += destW;
                        this.H = destH;
                        h = Math.Max(h, this.H);
                    }
                    break;
                case "Progress bar":
                    if (!(foregroundImg == null || Min == Max))
                    {
                        if (backgroundImg != null)
                            gfx.DrawImage(backgroundImg, left, y + setAlignment(align, zoomLength(backgroundImg.Height, Zoom), fixedH), zoomLength(backgroundImg.Width, Zoom), zoomLength(backgroundImg.Height, Zoom));

                        y += setAlignment(align, zoomLength(foregroundImg.Height, Zoom), fixedH);
                        int progress;

                        switch (Vector)
                        {
                            case "Left to right":
                                progress = (int)interpolateData(CurrDataValue, 0, foregroundImg.Width);
                                gfx.DrawImage(foregroundImg, new Rectangle(left, y, zoomLength(progress, Zoom), zoomLength(foregroundImg.Height, Zoom)), new Rectangle(0, 0, progress, foregroundImg.Height), GraphicsUnit.Pixel);
                                break;
                            case "Right to left":
                                progress = (int)interpolateData(CurrDataValue, 0, foregroundImg.Width);
                                gfx.DrawImage(foregroundImg, new Rectangle(left + zoomLength(foregroundImg.Width - progress, Zoom), y, zoomLength(progress, Zoom), zoomLength(foregroundImg.Height, Zoom)), new Rectangle(foregroundImg.Width - progress, 0, progress, foregroundImg.Height), GraphicsUnit.Pixel);
                                break;
                            case "Bottom to top":
                                progress = (int)interpolateData(CurrDataValue, 0, foregroundImg.Height);
                                gfx.DrawImage(foregroundImg, new Rectangle(left, y + zoomLength(foregroundImg.Height - progress, Zoom), zoomLength(foregroundImg.Width, Zoom), zoomLength(progress, Zoom)), new Rectangle(0, foregroundImg.Height - progress, foregroundImg.Width, progress), GraphicsUnit.Pixel);
                                break;
                            case "Top to bottom":
                                progress = (int)interpolateData(CurrDataValue, 0, foregroundImg.Height);
                                gfx.DrawImage(foregroundImg, new Rectangle(left, y, zoomLength(foregroundImg.Width, Zoom), zoomLength(progress, Zoom)), new Rectangle(0, 0, foregroundImg.Width, progress), GraphicsUnit.Pixel);
                                break;
                            case "Radial":
                                TextureBrush foreBrush = new TextureBrush(foregroundImg);
                                progress = (int)interpolateData(CurrDataValue, 0, Math.Min(foregroundImg.Width, foregroundImg.Height));

                                gfx.TranslateTransform(left, y);
                                gfx.ScaleTransform((float)Zoom / 100, (float)Zoom / 100);

                                gfx.FillEllipse(foreBrush, (foregroundImg.Width - progress) / 2, (foregroundImg.Height - progress) / 2, progress, progress);

                                gfx.ResetTransform();
                                foreBrush.Dispose();
                                break;
                        }

                        if (backgroundImg != null)
                        {
                            left += Math.Max(zoomLength(backgroundImg.Width, Zoom), zoomLength(foregroundImg.Width, Zoom));
                            this.H = Math.Max(zoomLength(backgroundImg.Height, Zoom), zoomLength(foregroundImg.Height, Zoom));
                        }
                        else
                        {
                            left += zoomLength(foregroundImg.Width, Zoom);
                            this.H = zoomLength(foregroundImg.Height, Zoom);
                        }

                        h = Math.Max(h, this.H);
                    }
                    break;
                case "Image sequence":
                    if (!(imgSeq == null || imgSeq.Length == 0 || Min == Max))
                    {
                        int imgInd = (int)interpolateData(CurrDataValue, 0, imgSeq.Length);
                        imgInd = Math.Max(Math.Min(imgInd, imgSeq.Length - 1), 0);

                        int destW = zoomLength(imgSeq[imgInd].Width, Zoom);
                        int destH = zoomLength(imgSeq[imgInd].Height, Zoom);

                        y += setAlignment(align, destH, fixedH);

                        gfx.DrawImage(imgSeq[imgInd], left, y, destW, destH);

                        left += destW;
                        this.H = destH;
                        h = Math.Max(h, this.H);
                    }
                    break;
                case "Graph":
                    if (!(GraphW == 0 || GraphH == 0 || Min == Max))
                    {
                        //init
                        if (graphValues == null)
                            graphValues = new List<float>();
                        if (graphPen == null)
                            graphPen = new Pen(GraphLineColor, GraphLineW);

                        gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                        if (DateTime.Now.Subtract(prevGraphTick).TotalMilliseconds >= GraphInterval)
                        {
                            //get new value
                            graphValues.Add(interpolateData(CurrDataValue, GraphH, 1));
                            if (graphValues.Count > Math.Ceiling((float)GraphW / GraphStepW) + 1)
                                graphValues.RemoveAt(0); //discard last value when graph too large

                            prevGraphTick = DateTime.Now;
                        }

                        //build graph path
                        GraphicsPath path = new GraphicsPath();
                        float x = left + GraphW;
                        y += setAlignment(align, GraphH, fixedH) + GraphLineW / 2;

                        for (int i = graphValues.Count - 1; i >= 1; i--)
                        {
                            path.AddLine(x, y + graphValues[i], x - GraphStepW, y + graphValues[i - 1]);
                            x -= GraphStepW;
                        }

                        //draw graph
                        gfx.DrawPath(graphPen, path);

                        //fill texture
                        if (graphTexImg != null)
                        {
                            //finish path
                            if (GraphTexFront)
                            {
                                path.AddLine(x, y + graphValues[0], x, y + GraphH);
                                path.AddLine(x, y + GraphH, left + GraphW, y + GraphH);
                                path.AddLine(left + GraphW, y + GraphH, left + GraphW, y + graphValues[graphValues.Count - 1]);
                            }
                            else
                            {
                                path.AddLine(x, y + graphValues[0], x, y);
                                path.AddLine(x, y, left + GraphW, y);
                                path.AddLine(left + GraphW, y, left + GraphW, y + graphValues[graphValues.Count - 1]);
                            }

                            //draw texture to img (because the texture can be an animated gif, and this will copy its current state)
                            int destW = (int)((float)Zoom / 100 * graphTexImg.Width);
                            int destH = (int)((float)Zoom / 100 * graphTexImg.Height);

                            Image temp = new Bitmap(destW, destH);
                            Graphics tempGfx = Graphics.FromImage(temp);

                            tempGfx.DrawImage(graphTexImg, 0, 0, destW, destH);
                            TextureBrush tex = new TextureBrush(temp);

                            //fill path with the texture
                            gfx.FillPath(tex, path);

                            //cleanup
                            tex.Dispose();
                            tempGfx.Dispose();
                            temp.Dispose();
                        }

                        if (GraphBorder)
                        {
                            //draw border
                            int right = left + GraphW;
                            int bottom = GraphH;

                            gfx.DrawLine(graphPen, left, y, right, y);
                            gfx.DrawLine(graphPen, right, y, right, y + bottom);
                            gfx.DrawLine(graphPen, left, y + bottom, right, y + bottom);
                            gfx.DrawLine(graphPen, left, y, left, y + bottom);
                        }

                        left += GraphW + (GraphBorder ? 1 : 0);
                        this.H = GraphH + (GraphBorder ? 1 : 0);
                        h = Math.Max(h, this.H);
                    }
                    break;
                case "Dota-style clock":
                    if (!(clockDayBrush == null || clockNightBrush == null || clockFrame == null || clockDayIcon == null || clockNightIcon == null))
                    {
                        //calculate clock rotation
                        if (DateTime.Now > clockNextUpdate)
                        {
                            DisposeImg(clockRotatedOrb); //cleanup previous orb

                            //recalculate sunrise/sunset times if new day
                            if (clockSunrise.Date != DateTime.Now.Date)
                            {
                                calcTwilights();

                                //generate orb with new day/night ratio
                                clockDayAngle = 360.0f * (float)(clockSunset - clockSunrise).TotalSeconds / (60 * 60 * 24);
                                int orbSize = clockDayBrush.Image.Width;

                                DisposeImg(clockOrb);
                                clockOrb = new Bitmap(orbSize, orbSize);

                                Graphics tempOrbGfx = Graphics.FromImage(clockOrb);
                                tempOrbGfx.FillPie(clockDayBrush, 0, 0, orbSize, orbSize, -90, clockDayAngle);
                                tempOrbGfx.FillPie(clockNightBrush, 0, 0, orbSize, orbSize, -90 + clockDayAngle, 360 - clockDayAngle);
                                tempOrbGfx.Dispose();
                            }

                            //rotate orb
                            float rotAngle;
                            if (DateTime.Now < clockSunrise)
                                //before sunrise
                                rotAngle = (360.0f - clockDayAngle) * (clockSunrise - DateTime.Now).Ticks / (clockSunrise - clockYesterdaySunset).Ticks;
                            else if (DateTime.Now < clockSunset)
                                //daytime
                                rotAngle = -clockDayAngle * (DateTime.Now - clockSunrise).Ticks / (clockSunset - clockSunrise).Ticks;
                            else
                                //after sunset
                                rotAngle = -clockDayAngle - (360.0f - clockDayAngle) * (DateTime.Now - clockSunset).Ticks / (clockTomorrowSunrise - clockSunset).Ticks;

                            clockRotatedOrb = new Bitmap(clockOrb.Width, clockOrb.Height);

                            Graphics tempGfx = Graphics.FromImage(clockRotatedOrb);
                            tempGfx.TranslateTransform(clockOrb.Width / 2, clockOrb.Height / 2);
                            tempGfx.RotateTransform(rotAngle);
                            tempGfx.TranslateTransform(-clockOrb.Width / 2, -clockOrb.Height / 2);
                            tempGfx.DrawImage(clockOrb, 0, 0, clockOrb.Width, clockOrb.Height);
                            tempGfx.Dispose();

                            //sound notifications
                            bool daytime = clockSunrise < DateTime.Now && DateTime.Now < clockSunset;

                            if (ClockPlaySounds)
                                switch (prevUpdateStatus)
                                {
                                    case UpdateStatus.FirstUpdate:
                                        if (ClockPlaySoundsOnStartup && clockSunrise < DateTime.Now && DateTime.Now.Hour < 12)
                                            Misc.PlaySound(imgsDir + "dota_clock\\morning.wav");

                                        if (daytime)
                                            prevUpdateStatus = UpdateStatus.Day;
                                        else
                                            prevUpdateStatus = UpdateStatus.Night;
                                        break;
                                    case UpdateStatus.Day:
                                        if (!daytime)
                                        {
                                            Misc.PlaySound(imgsDir + "dota_clock\\night.wav");
                                            prevUpdateStatus = UpdateStatus.Night;
                                        }
                                        break;
                                    case UpdateStatus.Night:
                                        if (daytime)
                                        {
                                            Misc.PlaySound(imgsDir + "dota_clock\\morning.wav");
                                            prevUpdateStatus = UpdateStatus.Day;
                                        }
                                        break;
                                }

                            //set time for next update
                            clockNextUpdate = DateTime.Now.AddMinutes(5);

                            if (daytime)
                            {
                                if (clockSunset < clockNextUpdate)
                                    clockNextUpdate = clockSunset;
                            }
                            else
                            {
                                if (clockSunrise < clockNextUpdate)
                                    clockNextUpdate = clockSunrise;
                            }
                        }

                        //set clock height if window is set to autosize
                        if (fixedH == 0)
                            fixedH = zoomLength(112, Zoom);

                        //calc sizes of clock elements
                        int midX = left + zoomLength(clockFrame.Width / 2, Zoom);
                        int frameW = zoomLength(clockFrame.Width, Zoom);
                        int frameH = zoomLength(clockFrame.Height, Zoom);

                        y = fixedH - frameH; //ignore TopMargin and set y-coordinate such that the clock is drawn at the bottom of the window

                        int orbH = zoomLength(clockOrb.Height, Zoom);
                        int orbY = y + zoomLength(29, Zoom) + clockYOffset;
                        int iconW = zoomLength(clockDayIcon.Width, (int)(Zoom * 1.33));
                        int iconH = zoomLength(clockDayIcon.Height, (int)(Zoom * 1.33));

                        //clock animation?
                        if (ClockMouseover)
                        {
                            //hide frame and show orb in full
                            int orbMinY = Math.Max(y + frameH - orbH, 0);

                            if (orbY > orbMinY)
                            {
                                orbY -= 2;
                                clockYOffset -= 2;

                                if (orbY < orbMinY)
                                {
                                    clockYOffset += orbMinY - orbY;
                                    orbY = orbMinY;
                                }
                            }
                        }
                        else if (clockYOffset < 0)
                        {
                            //reverse animation until beginning
                            clockYOffset += 2;

                            if (clockYOffset > 0)
                                clockYOffset = 0;
                        }

                        //draw clock
                        gfx.DrawImage(clockRotatedOrb, midX - zoomLength(clockOrb.Width, Zoom) / 2 + 1, orbY, zoomLength(clockOrb.Width, Zoom), orbH);

                        if (clockYOffset == 0)
                        {
                            gfx.DrawImage(clockFrame, left, y, frameW, frameH);

                            if (clockSunrise < DateTime.Now && DateTime.Now < clockSunset)
                                gfx.DrawImage(clockDayIcon, midX - iconW / 2 + 1, y + zoomLength(2, Zoom), iconW, iconH);
                            else
                                gfx.DrawImage(clockNightIcon, midX - iconW / 2 + 1, y + zoomLength(2, Zoom), iconW, iconH);

                            string time;
                            if (Clock24HrFormat)
                                time = DateTime.Now.ToString("H:mm");
                            else
                                time = DateTime.Now.ToString("h:mm");

                            var textSize = gfx.MeasureString(time, font);
                            gfx.DrawString(time, font, textBrush, midX - textSize.Width / 2, y + frameH - textSize.Height);
                        }

                        left += frameW;
                        this.H = fixedH;
                        h = Math.Max(h, this.H);
                    }
                    break;
            }

            prevDraw = DateTime.Now;
        }
 internal void FinishLine(DeviceChunkLine line, TextAlign align, VertAlign valign)
 {
     if (line!=null)
     {
         line.HorzAlign(align);
         line.VertAlign(valign);
     }
 }
Beispiel #14
0
 /// <summary>
 /// Align column content vertical top, bottom, center
 /// </summary>
 /// <param name="vertAlign"></param>
 /// <returns></returns>
 public DataBuilder <T> VertAlign(VertAlign vertAlign)
 {
     _column.VertAlign = vertAlign;
     return(this);
 }
Beispiel #15
0
        void loadOptions()
        {
            try
            {
                StreamReader file = new StreamReader(Application.StartupPath + "\\options.txt");

                this.Left = int.Parse(file.ReadLine());
                this.Top = int.Parse(file.ReadLine());

                //timerRefresh.Interval = int.Parse(file.ReadLine());
                timerUpdateData.Interval = int.Parse(file.ReadLine());

                this.Opacity = double.Parse(file.ReadLine().Replace('.', ','));
                fixedH = int.Parse(file.ReadLine());
                this.BackColor = Color.FromArgb(int.Parse(file.ReadLine()), int.Parse(file.ReadLine()), int.Parse(file.ReadLine()));
                this.TransparencyKey = this.BackColor;
                align = (VertAlign)Enum.Parse(typeof(VertAlign), file.ReadLine());
                this.TopMost = bool.Parse(file.ReadLine());
                this.AllowTransparency = bool.Parse(file.ReadLine());
                font = new Font(file.ReadLine(), int.Parse(file.ReadLine()), Misc.GenFontStyle(bool.Parse(file.ReadLine()), bool.Parse(file.ReadLine()), bool.Parse(file.ReadLine()), bool.Parse(file.ReadLine())));
                textColor = Color.FromArgb(int.Parse(file.ReadLine()), int.Parse(file.ReadLine()), int.Parse(file.ReadLine()));

                file.Close();
            }
            catch
            {
                MessageBox.Show("Your options file is either corrupt or made with a previous version of SysMana.", "Error while loading options", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            menuOnTop.Checked = this.TopMost;

            if (textBrush != null)
                textBrush.Dispose();
            textBrush = new SolidBrush(textColor);
        }
 static void ExctractAligns(HtmlChunkTag tag, ref TextAlign align, ref VertAlign valign)
 {
     var tmp = tag.GetAttr("ALIGN");
     if (tmp != null)
     {
         switch (tmp.ToUpperInvariant())
         {
             case "CENTER":
                 align = TextAlign.Center;
                 break;
             case "JUSTIFY":
                 align = TextAlign.Justify;
                 break;
             case "RIGHT":
                 align = TextAlign.Right;
                 break;
             case "LEFT":
                 align = TextAlign.Left;
                 break;
             default:
                 HtEngine.Log(HtLogLevel.Warning, "Invalid attribute align: '{0}'", tmp);
                 align = TextAlign.Left;
                 break;
         }
     }
     else
     {
         //align = TextAlign.Left;
     }
     tmp = tag.GetAttr("VALIGN");
     if (tmp != null)
     {
         switch (tmp.ToUpperInvariant())
         {
             case "MIDDLE":
                 valign = VertAlign.Middle;
                 break;
             case "TOP":
                 valign = VertAlign.Top;
                 break;
             case "BOTTOM":
                 valign = VertAlign.Bottom;
                 break;
             default:
                 HtEngine.Log(HtLogLevel.Warning, "Invalid attribute valign: '{0}'", tmp);
                 valign = VertAlign.Bottom;
                 break;
         }
     }
     else
     {
         //valign = VertAlign.Bottom;
     }
 }
Beispiel #17
0
        private string XmlAlign(HorzAlign horzAlign, VertAlign vertAlign, int angle)
        {
            string Fh = "Left", Fv = "Top";

            if (angle == 0 || angle == 180)
            {
                if (horzAlign == HorzAlign.Left)
                {
                    Fh = "Left";
                }
                else if (horzAlign == HorzAlign.Right)
                {
                    Fh = "Right";
                }
                else if (horzAlign == HorzAlign.Center)
                {
                    Fh = "Center";
                }
                else if (horzAlign == HorzAlign.Justify)
                {
                    Fh = "Justify";
                }
                if (vertAlign == VertAlign.Top)
                {
                    Fv = "Top";
                }
                else if (vertAlign == VertAlign.Bottom)
                {
                    Fv = "Bottom";
                }
                else if (vertAlign == VertAlign.Center)
                {
                    Fv = "Center";
                }
            }
            else if (angle == 90)
            {
                if (horzAlign == HorzAlign.Left)
                {
                    Fv = "Top";
                }
                else if (horzAlign == HorzAlign.Right)
                {
                    Fv = "Bottom";
                }
                else if (horzAlign == HorzAlign.Center)
                {
                    Fv = "Center";
                }
                if (vertAlign == VertAlign.Top)
                {
                    Fh = "Right";
                }
                else if (vertAlign == VertAlign.Bottom)
                {
                    Fh = "Left";
                }
                else if (vertAlign == VertAlign.Center)
                {
                    Fh = "Center";
                }
            }
            else
            {
                if (horzAlign == HorzAlign.Left)
                {
                    Fv = "Bottom";
                }
                else if (horzAlign == HorzAlign.Right)
                {
                    Fv = "Top";
                }
                else if (horzAlign == HorzAlign.Center)
                {
                    Fv = "Center";
                }
                if (vertAlign == VertAlign.Top)
                {
                    Fh = "Right";
                }
                else if (vertAlign == VertAlign.Bottom)
                {
                    Fh = "Left";
                }
                else if (vertAlign == VertAlign.Center)
                {
                    Fh = "Center";
                }
            }
            return("ss:Horizontal=\"" + Fh + "\" ss:Vertical=\"" + Fv + "\"");
        }
 /// <summary>
 /// Align report title content vertical top, bottom, center
 /// </summary>
 /// <param name="vertAlign"></param>
 /// <returns></returns>
 public ReportTitleBuilder <T> VertAlign(VertAlign vertAlign)
 {
     _report._reportTitle.VertAlign = vertAlign;
     return(this);
 }
Beispiel #19
0
        public void Init(List<Meter> meters, int refresh, int opacity, int fixedH, Color backColor, Color textColor, VertAlign align, bool topMost, bool transparent, Font font, DataSources data, Action LoadMeters, Action LoadOptions, Action InitData, Func<string, Image> LoadImg, Action<Image> DisposeImg)
        {
            initiating = true;

            this.data = data;
            this.LoadMeters = LoadMeters;
            this.LoadOptions = LoadOptions;
            this.InitData = InitData;
            this.LoadImg = LoadImg;
            this.DisposeImg = DisposeImg;

            //copy meters list
            this.meters = meters;

            listMeters.Items.Clear();
            foreach (Meter meter in meters)
                listMeters.Items.Add(meter.Data);

            //load system fonts
            comboFont.Items.Clear();

            foreach (FontFamily fontFamily in System.Drawing.FontFamily.Families)
                comboFont.Items.Add(fontFamily.Name);

            //display general options
            numRefresh.Value = refresh;
            numOpacity.Value = opacity;
            numFixedH.Value = fixedH;
            picBackColor.BackColor = backColor;
            picTextColor.BackColor = textColor;
            comboVertAlign.Text = align.ToString();
            checkTopMost.Checked = topMost;
            checkTransparent.Checked = transparent;

            comboFont.Text = font.Name;
            numFontSize.Value = (int)font.Size;
            checkFontBold.Checked = font.Bold;
            checkFontItalic.Checked = font.Italic;
            checkFontUnderline.Checked = font.Underline;
            checkFontStrikeout.Checked = font.Strikeout;

            //note current values of general options
            this.refresh = refresh;
            this.opacity = opacity;
            this.fixedH = fixedH;
            this.backColor = backColor;
            this.textColor = textColor;
            this.align = align;
            this.topMost = topMost;
            this.transparent = transparent;
            this.font = font;

            //runs at startup?
            RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

            if (rkApp.GetValue("SysMana") != null)
                checkRunAtStartup.Checked = true;

            initiating = false;

            buttMeterSaveChanges.Enabled = false;
            buttOptionsSaveChanges.Enabled = false;
        }
Beispiel #20
0
        private void buttOptionsSaveChanges_Click(object sender, EventArgs e)
        {
            //update values
            refresh = (int)numRefresh.Value;
            opacity = (int)numOpacity.Value;
            fixedH = (int)numFixedH.Value;
            backColor = picBackColor.BackColor;
            textColor = picTextColor.BackColor;
            align = (VertAlign)Enum.Parse(typeof(VertAlign), comboVertAlign.Text);
            topMost = checkTopMost.Checked;
            transparent = checkTransparent.Checked;

            font = new Font(comboFont.Text, (int)numFontSize.Value, Misc.GenFontStyle(checkFontBold.Checked, checkFontItalic.Checked, checkFontUnderline.Checked, checkFontStrikeout.Checked));

            //get most recent form position
            StreamReader fileRdr = new StreamReader(Application.StartupPath + "\\options.txt");
            int left = int.Parse(fileRdr.ReadLine());
            int top = int.Parse(fileRdr.ReadLine());
            fileRdr.Close();

            //save values
            StreamWriter file = new StreamWriter(Application.StartupPath + "\\options.txt");

            file.WriteLine(left);
            file.WriteLine(top);
            file.WriteLine(refresh);
            file.WriteLine(opacity);
            file.WriteLine(fixedH);
            file.WriteLine(backColor.R);
            file.WriteLine(backColor.G);
            file.WriteLine(backColor.B);
            file.WriteLine(align.ToString());
            file.WriteLine(topMost);
            file.WriteLine(transparent);
            file.WriteLine(font.Name);
            file.WriteLine(font.Size);
            file.WriteLine(font.Bold);
            file.WriteLine(font.Italic);
            file.WriteLine(font.Underline);
            file.WriteLine(font.Strikeout);
            file.WriteLine(textColor.R);
            file.WriteLine(textColor.G);
            file.WriteLine(textColor.B);

            file.Close();

            //load new values in main form
            LoadOptions();

            buttOptionsSaveChanges.Enabled = false;
        }
Beispiel #21
0
        int setAlignment(VertAlign align, int drawH, int fixedH)
        {
            if (fixedH == 0)
                return 0;

            switch (align)
            {
                default:
                case VertAlign.Top:
                    return 0;
                case VertAlign.Center:
                    return (fixedH - drawH) / 2;
                case VertAlign.Bottom:
                    return fixedH - drawH;
            }
        }
Beispiel #22
0
        public void Parse(IEnumerator <HtmlChunk> htmlChunks, int viewportWidth, string id = null, HtFont font = null, HtColor color = default(HtColor), TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
        {
            this.Clear();
            var defaultFont = HtEngine.Device.LoadFont(HtEngine.DefaultFontFace, HtEngine.DefaultFontSize, false, false);

            font  = font == null ? defaultFont : font;
            color = (color.R == 0 && color.G == 0 && color.B == 0 && color.A == 0) ? HtEngine.DefaultColor : color;
            //string id = null;
            //var align = TextAlign.Left;
            //var valign = VertAlign.Bottom;
            DrawTextDeco   deco         = DrawTextDeco.None;
            DrawTextEffect effect       = DrawTextEffect.None;
            HtColor        effectColor  = HtEngine.DefaultColor;
            int            effectAmount = 1;
            string         currentLink  = null;
            bool           prevIsWord   = false;

            DeviceChunkLine     currLine      = null;
            DeviceChunkDrawText lastTextChunk = null;

            //for (int i = 0; i < htmlChunks.Count; i++)
            while (htmlChunks.MoveNext())
            {
                HtmlChunk htmlChunk = htmlChunks.Current;

                var word = htmlChunk as HtmlChunkWord;
                if (word != null)
                {
                    if (currLine == null)
                    {
                        currLine = this.NewLine(null, viewportWidth, align, valign);
                    }

                    if (effect == DrawTextEffect.None)
                    {
                        lastTextChunk = AcquireDeviceChunkDrawText(
                            id,
                            word.Text,
                            font,
                            color,
                            deco,
                            lastTextChunk != null && lastTextChunk.Deco != deco,
                            prevIsWord);
                    }
                    else
                    {
                        lastTextChunk = AcquireDeviceChunkDrawTextEffect(
                            id,
                            word.Text,
                            font,
                            color,
                            deco,
                            lastTextChunk != null && lastTextChunk.Deco != deco,
                            effect,
                            effectAmount,
                            effectColor,
                            prevIsWord);
                    }

                    if (currentLink != null && !this.Links.ContainsKey(lastTextChunk))
                    {
                        this.Links.Add(lastTextChunk, currentLink);
                    }
                    if (!currLine.AddChunk(lastTextChunk, prevIsWord))
                    {
                        prevIsWord = true;
                        //currLine.IsFull = true;
                        string lastText = lastTextChunk.Text;
                        lastTextChunk.Dispose();
                        lastTextChunk = null;
                        bool decoStop = lastTextChunk != null && lastTextChunk.Deco != deco;

                        // find prefix ascii string.
                        //string prefixAsciiText = null;
                        int pos = 0;
                        //for (pos = 0; pos < lastText.Length; ++pos) {
                        //  char ch = lastText[pos];
                        //  if (ch > 255 || ch == ' ') {
                        //    prefixAsciiText = lastText.Substring(0, pos);
                        //    break;
                        //  }
                        //}
                        //if (prefixAsciiText != null) {
                        //  DeviceChunkDrawText prefixAsciiTextChunk;
                        //  if (effect == DrawTextEffect.None) {
                        //    prefixAsciiTextChunk = AcquireDeviceChunkDrawText(
                        //      id,
                        //      prefixAsciiText,
                        //      font,
                        //      color,
                        //      deco,
                        //      decoStop,
                        //      prevIsWord);
                        //  } else {
                        //    prefixAsciiTextChunk = AcquireDeviceChunkDrawTextEffect(
                        //      id,
                        //      prefixAsciiText,
                        //      font,
                        //      color,
                        //      deco,
                        //      decoStop,
                        //      effect,
                        //      effectAmount,
                        //      effectColor,
                        //      prevIsWord);
                        //  }
                        //  if (currLine.AddChunk(prefixAsciiTextChunk, prevIsWord)) {
                        //    if (currentLink != null && !this.Links.ContainsKey(prefixAsciiTextChunk))
                        //      this.Links.Add(prefixAsciiTextChunk, currentLink);
                        //    lastText = lastText.Substring(pos);
                        //    decoStop = false;
                        //  }
                        //}
                        //// reset the pos.
                        //pos = 0;

                        // add multi-lines.
                        int remainingWidth = viewportWidth;
                        for (; pos < lastText.Length;)
                        {
                            char ch = lastText[pos];
                            remainingWidth -= font.Measure(ch.ToString()).Width;
                            if (remainingWidth < 0)
                            {
                                string tmpText = lastText.Substring(0, pos);
                                DeviceChunkDrawText tmpTextChunk;
                                if (effect == DrawTextEffect.None)
                                {
                                    tmpTextChunk = AcquireDeviceChunkDrawText(
                                        id,
                                        tmpText,
                                        font,
                                        color,
                                        deco,
                                        decoStop,
                                        prevIsWord);
                                }
                                else
                                {
                                    tmpTextChunk = AcquireDeviceChunkDrawTextEffect(
                                        id,
                                        tmpText,
                                        font,
                                        color,
                                        deco,
                                        decoStop,
                                        effect,
                                        effectAmount,
                                        effectColor,
                                        prevIsWord);
                                }

                                currLine = this.NewLine(currLine, viewportWidth, align, valign);
                                currLine.AddChunk(tmpTextChunk, prevIsWord);
                                if (currentLink != null && !this.Links.ContainsKey(tmpTextChunk))
                                {
                                    this.Links.Add(tmpTextChunk, currentLink);
                                }
                                lastText       = lastText.Substring(pos);
                                pos            = 0;
                                remainingWidth = viewportWidth;
                            }
                            else
                            {
                                ++pos;
                            }
                        }

                        // add last line.
                        if (!string.IsNullOrEmpty(lastText))
                        {
                            if (effect == DrawTextEffect.None)
                            {
                                lastTextChunk = AcquireDeviceChunkDrawText(
                                    id,
                                    lastText,
                                    font,
                                    color,
                                    deco,
                                    decoStop,
                                    prevIsWord);
                            }
                            else
                            {
                                lastTextChunk = AcquireDeviceChunkDrawTextEffect(
                                    id,
                                    lastText,
                                    font,
                                    color,
                                    deco,
                                    decoStop,
                                    effect,
                                    effectAmount,
                                    effectColor,
                                    prevIsWord);
                            }

                            currLine = this.NewLine(currLine, viewportWidth, align, valign);
                            currLine.AddChunk(lastTextChunk, prevIsWord);
                            if (currentLink != null && !this.Links.ContainsKey(lastTextChunk))
                            {
                                this.Links.Add(lastTextChunk, currentLink);
                            }
                        }
                    }
                    prevIsWord = true;
                }
                else
                {
                    prevIsWord = false;
                }

                var tag = htmlChunk as HtmlChunkTag;
                if (tag != null)
                {
                    switch (tag.Tag)
                    {
                    case "spin":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            id = null;
                            this.FinishLine(currLine, align, valign);
                            return;     // return control to parent
                        }
                        else
                        {
                            id = tag.GetAttr("id");
                            ExctractAligns(tag, ref align, ref valign);
                            var compiled = OP <DeviceChunkDrawCompiled> .Acquire();

                            compiled.Font = font;
                            var scompiledWidth = tag.GetAttr("width") ?? "0";
                            var compiledWidth  = 0;
                            if (!int.TryParse(scompiledWidth, out compiledWidth))
                            {
                                compiledWidth = 0;
                            }
                            if (compiledWidth == 0)
                            {
                                compiledWidth = currLine == null ? viewportWidth : currLine.AvailWidth - font.WhiteSize;
                            }
                            if (compiledWidth > 0)
                            {
                                if (compiledWidth > viewportWidth)
                                {
                                    compiledWidth = viewportWidth;
                                }
                                compiled.Parse(htmlChunks, compiledWidth, id, font, color, align, valign);
                                compiled.MeasureSize();
                                if (currLine == null)
                                {
                                    currLine = this.NewLine(null, viewportWidth, align, valign);
                                }

                                if (!currLine.AddChunk(compiled, prevIsWord))
                                {
                                    currLine.IsFull = true;
                                    currLine        = this.NewLine(currLine, viewportWidth, align, valign);
                                    if (!currLine.AddChunk(compiled, prevIsWord))
                                    {
                                        HtEngine.Log(HtLogLevel.Error, "Could not fit spin into line. Word is too big: {0}", lastTextChunk);
                                        compiled.Dispose();
                                        compiled = null;
                                    }
                                }
                            }
                            else
                            {
                                HtEngine.Log(HtLogLevel.Warning, "spin width is not given");
                            }
                        }
                        break;

                    case "effect":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            effect = DrawTextEffect.None;
                        }
                        else
                        {
                            var name = tag.GetAttr("name") ?? "outline";
                            switch (name)
                            {
                            case "shadow":
                                effect       = DrawTextEffect.Shadow;
                                effectAmount = 1;
                                effectColor  = HtColor.RGBA(0, 0, 0, 80);
                                break;

                            case "outline":
                                effect       = DrawTextEffect.Outline;
                                effectAmount = 1;
                                effectColor  = HtColor.RGBA(0xFF, 0xFF, 0xFF, 80);
                                break;
                            }
                            var amount = tag.GetAttr("amount");
                            if (amount != null)
                            {
                                if (!int.TryParse(amount, out effectAmount))
                                {
                                    HtEngine.Log(HtLogLevel.Error, "Invalid numeric value: " + amount);
                                }
                            }
                            var colors = tag.GetAttr("color");
                            if (colors != null)
                            {
                                effectColor = HtColor.Parse(colors);
                            }
                        }
                        break;

                    case "u":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            deco &= ~DrawTextDeco.Underline;
                        }
                        else
                        {
                            deco |= DrawTextDeco.Underline;
                        }
                        break;

                    case "s":
                    case "strike":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            deco &= ~DrawTextDeco.Strike;
                        }
                        else
                        {
                            deco |= DrawTextDeco.Strike;
                        }
                        break;

                    case "code":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                        }
                        else
                        {
                            this.fontStack.Push(font);

                            const string fontName = "code";
                            int          fontSize = font.Size;
                            bool         fontBold = font.Bold;
                            bool         fontItal = font.Italic;

                            font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);
                        }
                        break;

                    case "b":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                        }
                        else
                        {
                            this.fontStack.Push(font);

                            string     fontName = font.Face;
                            int        fontSize = font.Size;
                            const bool fontBold = true;
                            bool       fontItal = font.Italic;

                            font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);
                        }
                        break;

                    case "i":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                        }
                        else
                        {
                            this.fontStack.Push(font);

                            string     fontName = font.Face;
                            int        fontSize = font.Size;
                            bool       fontBold = font.Bold;
                            const bool fontItal = true;

                            font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);
                        }
                        break;

                    case "a":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            id = null;
                            if (this.colorStack.Count > 0)
                            {
                                color = this.colorStack.Pop();
                            }
                            currentLink = null;
                        }
                        else
                        {
                            id          = tag.GetAttr("id");
                            currentLink = tag.GetAttr("href");
                            this.colorStack.Push(color);
                            color = HtEngine.DefaultLinkColor;
                        }
                        break;

                    case "font":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            font  = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                            color = this.colorStack.Count > 0 ? this.colorStack.Pop() : HtEngine.DefaultColor;
                        }
                        else
                        {
                            this.fontStack.Push(font);
                            this.colorStack.Push(color);

                            string fontName  = tag.GetAttr("face") ?? font.Face;
                            string fontSizeS = tag.GetAttr("size");
                            int    fontSize;
                            if (fontSizeS == null || !int.TryParse(fontSizeS, out fontSize))
                            {
                                fontSize = font.Size;
                            }
                            bool fontBold = font.Bold;
                            bool fontItal = font.Italic;

                            font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);

                            color = HtColor.Parse(tag.GetAttr("color"), color);
                        }
                        break;

                    case "br":
                        currLine        = this.NewLine(currLine, viewportWidth, align, valign);
                        currLine.Height = font.LineSpacing;
                        break;

                    case "img":
                        if (tag.IsClosing)
                        {
                            // ignore closing tags
                        }
                        else
                        {
                            var src = tag.GetAttr("src");
                            var widthS = tag.GetAttr("width");
                            var heightS = tag.GetAttr("height");
                            var fpsS = tag.GetAttr("fps");
                            var imgId = tag.GetAttr("id");
                            int w, h, fps;
                            if (widthS == null || !int.TryParse(widthS, out w))
                            {
                                w = -1;
                            }
                            if (heightS == null || !int.TryParse(heightS, out h))
                            {
                                h = -1;
                            }
                            if (fpsS == null || !int.TryParse(fpsS, out fps))
                            {
                                fps = -1;
                            }
                            var img = HtEngine.Device.LoadImage(src, fps);
                            if (w < 0)
                            {
                                w = img.Width;
                            }
                            if (h < 0)
                            {
                                h = img.Height;
                            }
                            var dChunk = OP <DeviceChunkDrawImage> .Acquire();

                            if (currLine == null)
                            {
                                currLine = this.NewLine(null, viewportWidth, align, valign);
                            }
                            dChunk.Image       = img;
                            dChunk.Rect.Width  = w;
                            dChunk.Rect.Height = h;
                            dChunk.Font        = font; // for whitespace measure
                            dChunk.Id          = imgId;
                            //HtEngine.Log(HtLogLevel.Debug, "Adding image w={0} h={1}",dChunk.Width,dChunk.Height);
                            if (currentLink != null && !this.Links.ContainsKey(dChunk))
                            {
                                this.Links.Add(dChunk, currentLink);
                            }
                            if (!currLine.AddChunk(dChunk, prevIsWord))
                            {
                                currLine.IsFull = true;
                                currLine        = this.NewLine(currLine, viewportWidth, align, valign);
                                if (!currLine.AddChunk(dChunk, prevIsWord))
                                {
                                    HtEngine.Log(HtLogLevel.Error, "Could not fit image into line. Image is too big: {0}", dChunk);
                                    dChunk.Dispose();
                                }
                            }
                        }
                        break;

                    case "p":
                        if (tag.IsClosing)
                        {
                            id = null;
                        }
                        else
                        {
                            id       = tag.GetAttr("id");
                            currLine = this.NewLine(currLine, viewportWidth, align, valign);

                            ExctractAligns(tag, ref align, ref valign);
                        }

                        break;

                    default:
                        HtEngine.Log(HtLogLevel.Error, "Unsupported html tag {0}", tag);
                        break;
                    }
                }
            }

            // align last line
            this.FinishLine(currLine, align, valign);
        }
Beispiel #23
0
 public override string ToString()
 {
     return(Align.ToString() + ", " + VertAlign.ToString() + ", " + LineSpacing);
 }
        public void Parse(IEnumerator<HtmlChunk> htmlChunks, int viewportWidth, TextAlign align=TextAlign.Left, VertAlign valign=VertAlign.Bottom)
        {
            this.Clear();
            var defaultFont = HtEngine.Device.LoadFont(HtEngine.DefaultFontFace, HtEngine.DefaultFontSize, false, false);
            var font = defaultFont;
            var color = HtEngine.DefaultColor;
            //var align = TextAlign.Left;
            //var valign = VertAlign.Bottom;
            DrawTextDeco deco = DrawTextDeco.None;
            DrawTextEffect effect = DrawTextEffect.None;
            HtColor effectColor = HtEngine.DefaultColor;
            int effectAmount = 1;
            string currentLink = null;

            
            DeviceChunkLine currLine = null;
            DeviceChunkDrawText lastTextChunk=null;

            //for (int i = 0; i < htmlChunks.Count; i++)
            while(htmlChunks.MoveNext())
            {
                HtmlChunk htmlChunk = htmlChunks.Current;

                var word = htmlChunk as HtmlChunkWord;
                if (word != null)
                {
                    if (currLine==null)
                    {
                        currLine = this.NewLine(null, viewportWidth, align, valign);
                    }

                    if (effect == DrawTextEffect.None)
                    {
                        var textChunk = OP<DeviceChunkDrawText>.Acquire();
                        textChunk.Text = word.Text;
                        textChunk.Font = font;
                        textChunk.Color = color;
                        textChunk.Deco = deco;
                        if (lastTextChunk!=null && lastTextChunk.Deco!=deco)
                        {
                            lastTextChunk.DecoStop = true;
                        }
                        textChunk.MeasureSize();
                        lastTextChunk = textChunk;
                    }
                    else
                    {
                        var textChunk = OP<DeviceChunkDrawTextEffect>.Acquire();
                        textChunk.Text = word.Text;
                        textChunk.Font = font;
                        textChunk.Color = color;
                        textChunk.Deco = deco;
                        if (lastTextChunk != null && lastTextChunk.Deco != deco)
                        {
                            lastTextChunk.DecoStop = true;
                        }
                        textChunk.Effect = effect;
                        textChunk.EffectAmount = effectAmount;
                        textChunk.EffectColor = effectColor;
                        textChunk.MeasureSize();
                        lastTextChunk = textChunk;
                    }

                    if (currentLink!=null)
                        this.Links.Add(new KeyValuePair<DeviceChunk, string>(lastTextChunk, currentLink));
                    if (!currLine.AddChunk(lastTextChunk))
                    {
                        currLine.IsFull = true;
                        currLine = this.NewLine(currLine, viewportWidth, align, valign);
                        if (!currLine.AddChunk(lastTextChunk))
                        {
                            HtEngine.Log(HtLogLevel.Error, "Could not fit word into line. Word is too big: {0}", lastTextChunk);
                            lastTextChunk.Dispose();
                            lastTextChunk = null;
                        }
                    }
                }

                var tag = htmlChunk as HtmlChunkTag;
                if (tag != null)
                {
                    switch (tag.Tag)
                    {
                        case "div":
                            if (tag.IsSingle)
                            {
                                // do nothing
                            }
                            else if (tag.IsClosing)
                            {
                                this.FinishLine(currLine,align,valign);
                                return; // return control to parent
                            }
                            else
                            {
                                ExctractAligns(tag, ref align, ref valign);
                                var compiled = OP<DeviceChunkDrawCompiled>.Acquire();
                                compiled.Font = font;
                                var scompiledWidth = tag.GetAttr("width") ?? "0";
                                var compiledWidth = 0;
                                if (!int.TryParse(scompiledWidth, out compiledWidth)) compiledWidth = 0;
                                if (compiledWidth==0)
                                {
                                    compiledWidth = currLine == null ? viewportWidth : currLine.AvailWidth-font.WhiteSize;
                                }
                                if (compiledWidth>0)
                                {
                                    compiled.Parse(htmlChunks, compiledWidth, align, valign);
                                    compiled.MeasureSize();
                                    if (currLine == null)
                                    {
                                        currLine = this.NewLine(null, viewportWidth, align, valign);
                                    }

                                    if (!currLine.AddChunk(compiled))
                                    {
                                        currLine.IsFull = true;
                                        currLine = this.NewLine(currLine, viewportWidth, align, valign);
                                        if (!currLine.AddChunk(compiled))
                                        {
                                            HtEngine.Log(HtLogLevel.Error, "Could not fit div into line. Word is too big: {0}", lastTextChunk);
                                            compiled.Dispose();
                                            compiled = null;
                                        }
                                    }
                                }
                                else
                                {
                                    HtEngine.Log(HtLogLevel.Warning, "div width is not given");
                                }
                            }
                            break;
                        case "effect":
                            if (tag.IsSingle)
                            {
                                // do nothing
                            }
                            else if (tag.IsClosing)
                            {
                                effect = DrawTextEffect.None;
                            }
                            else
                            {
                                var name = tag.GetAttr("name") ?? "outline";
                                switch (name)
                                {
                                    case "shadow":
                                        effect = DrawTextEffect.Shadow;
                                        effectAmount = 1;
                                        effectColor = HtColor.RGBA(0, 0, 0, 80);
                                        break;
                                    case "outline":
                                        effect = DrawTextEffect.Outline;
                                        effectAmount = 1;
                                        effectColor = HtColor.RGBA(0xFF, 0xFF, 0xFF, 80);
                                        break;
                                }
                                var amount = tag.GetAttr("amount");
                                if (amount!=null)
                                {
                                    if (!int.TryParse(amount,out effectAmount))
                                    {
                                        HtEngine.Log(HtLogLevel.Error, "Invalid numeric value: " + amount);
                                    }
                                }
                                var colors = tag.GetAttr("color");
                                if (colors != null) effectColor = HtColor.Parse(colors);
                            }
                            break;
                        case "u":
                            if (tag.IsSingle)
                            {
                                // do nothing
                            }
                            else if (tag.IsClosing)
                            {
                                deco &= ~DrawTextDeco.Underline;
                            }
                            else
                            {
                                deco |= DrawTextDeco.Underline;
                            }
                            break;
                        case "s":
                        case "strike":
                            if (tag.IsSingle)
                            {
                                // do nothing
                            }
                            else if (tag.IsClosing)
                            {
                                deco &= ~DrawTextDeco.Strike;
                            }
                            else
                            {
                                deco |= DrawTextDeco.Strike;
                            }
                            break;
                        case "code":
                            if (tag.IsSingle)
                            {
                                // do nothing
                            }
                            else if (tag.IsClosing)
                            {
                                font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                            }
                            else
                            {
                                this.fontStack.Push(font);

                                const string fontName = "code";
                                int fontSize = font.Size;
                                bool fontBold = font.Bold;
                                bool fontItal = font.Italic;

                                font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);
                            }
                            break;

                        case "b":
                            if (tag.IsSingle)
                            {
                                // do nothing
                            }
                            else if (tag.IsClosing)
                            {
                                font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                            }
                            else
                            {
                                this.fontStack.Push(font);

                                string fontName = font.Face;
                                int fontSize = font.Size;
                                const bool fontBold = true;
                                bool fontItal = font.Italic;

                                font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);
                            }
                            break;
                        case "i":
                            if (tag.IsSingle)
                            {
                                // do nothing
                            }
                            else if (tag.IsClosing)
                            {
                                font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                            }
                            else
                            {
                                this.fontStack.Push(font);

                                string fontName = font.Face;
                                int fontSize = font.Size;
                                bool fontBold = font.Bold;
                                const bool fontItal = true;

                                font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);
                            }
                            break;
                        case "a":
                            if (tag.IsSingle)
                            {
                                // do nothing
                            }
                            else if (tag.IsClosing)
                            {
                                if (this.colorStack.Count>0)
                                    color = this.colorStack.Pop();
                                currentLink = null;
                            }
                            else
                            {
                                currentLink = tag.GetAttr("href");
                                this.colorStack.Push(color);
                                color = HtEngine.DefaultLinkColor;
                            }
                            break;

                        case "font":
                            if (tag.IsSingle)
                            {
                                // do nothing
                            }
                            else if (tag.IsClosing)
                            {
                                font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                                color = this.colorStack.Count > 0 ? this.colorStack.Pop() : HtEngine.DefaultColor;
                            }
                            else
                            {
                                this.fontStack.Push(font);
                                this.colorStack.Push(color);

                                string fontName = tag.GetAttr("face") ?? font.Face;
                                string fontSizeS = tag.GetAttr("size");
                                int fontSize;
                                if (fontSizeS == null || !int.TryParse(fontSizeS, out fontSize)) fontSize = font.Size;
                                bool fontBold = font.Bold;
                                bool fontItal = font.Italic;

                                font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);

                                color = HtColor.Parse(tag.GetAttr("color"), color);
                            }
                            break;
                        case "br":
                            currLine = this.NewLine(currLine, viewportWidth, align, valign);
                            currLine.Height = font.LineSpacing;
                            break;
                        case "img":
                            if (tag.IsClosing)
                            {
                                // ignore closing tags
                            }
                            else
                            {
                                var src = tag.GetAttr("src");
                                var widthS = tag.GetAttr("width");
                                var heightS = tag.GetAttr("height");
                                int w,h;
                                if (widthS == null || !int.TryParse(widthS, out w)) w = -1;
                                if (heightS == null || !int.TryParse(heightS, out h)) h = -1;
                                var img = HtEngine.Device.LoadImage(src);
                                if (w < 0) w = img.Width;
                                if (h < 0) h = img.Height;
                                var dChunk = OP<DeviceChunkDrawImage>.Acquire();
                                if (currLine == null)
                                    currLine = this.NewLine(null, viewportWidth, align, valign);
                                dChunk.Image = img;
                                dChunk.Rect.Width = w;
                                dChunk.Rect.Height = h;
                                dChunk.Font = font; // for whitespace measure
                                //HtEngine.Log(HtLogLevel.Debug, "Adding image w={0} h={1}",dChunk.Width,dChunk.Height);
                                if (currentLink != null)
                                    this.Links.Add(new KeyValuePair<DeviceChunk, string>(dChunk, currentLink));
                                if (!currLine.AddChunk(dChunk))
                                {
                                    currLine.IsFull = true;
                                    currLine = this.NewLine(currLine, viewportWidth, align, valign);
                                    if (!currLine.AddChunk(dChunk))
                                    {
                                        HtEngine.Log(HtLogLevel.Error, "Could not fit image into line. Image is too big: {0}", dChunk);
                                        dChunk.Dispose();
                                    }
                                }
                            }
                            break;
                        case "p":
                            if (tag.IsClosing)
                            {
                                // ignore closing tags
                            }
                            else
                            {
                                currLine = this.NewLine(currLine, viewportWidth, align, valign);

                                ExctractAligns(tag, ref align, ref valign);
                            }
                            
                            break;
                        default:
                            HtEngine.Log(HtLogLevel.Error, "Unsupported html tag {0}", tag);
                            break;
                    }
                }
            }

            // align last line
            this.FinishLine(currLine, align, valign);
        }
Beispiel #25
0
        private void DrawText(FRPaintEventArgs e, string text, Brush brush, float x, float y, HorAlign hAlign, VertAlign vAlign)
        {
            Graphics g       = e.Graphics;
            Font     font    = RadialUtils.GetFont(e, Parent, Font);
            SizeF    strSize = RadialUtils.GetStringSize(e, Parent, Font, text);
            float    dx      = 0;
            float    dy      = 0;

            if (hAlign == HorAlign.Middle)
            {
                dx = -strSize.Width / 2;
            }
            else if (hAlign == HorAlign.Left)
            {
                dx = 0;
            }
            else if (hAlign == HorAlign.Right)
            {
                dx = -strSize.Width;
            }

            if (vAlign == VertAlign.Bottom)
            {
                dy = -strSize.Height;
            }
            else if (vAlign == VertAlign.Middle)
            {
                dy = -strSize.Height / 2;
            }
            else if (vAlign == VertAlign.Top)
            {
                dy = 0;
            }
            g.DrawString(text, font, brush, x + dx, y + dy);
        }
 /// <summary>
 /// Aligns prev line, creates new line and applies Y to it
 /// </summary>
 /// <param name="prevLine">previous line</param>
 /// <param name="viewPortWidth">viewport width</param>
 /// <param name="prevAlign">text align</param>
 /// <param name="prevVAlign">vertical align</param>
 /// <returns>new empty line</returns>
 internal DeviceChunkLine NewLine(DeviceChunkLine prevLine, int viewPortWidth, TextAlign prevAlign, VertAlign prevVAlign)
 {
     int freeY = 0;
     if (prevLine!=null)
     {
         this.FinishLine(prevLine, prevAlign, prevVAlign);
         freeY = prevLine.Y + prevLine.Height;
     }
     var newLine = OP<DeviceChunkLine>.Acquire();
     newLine.MaxWidth = viewPortWidth;
     newLine.Y = freeY;
     this.list.Add(newLine);
     return newLine;
 }
Beispiel #27
0
		public void Parse(IEnumerator<HtmlChunk> htmlChunks, int viewportWidth, string id = null, HtFont font = null, HtColor color = default(HtColor), TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
		{
			this.Clear();
			var defaultFont = HtEngine.Device.LoadFont(HtEngine.DefaultFontFace, HtEngine.DefaultFontSize, false, false, 0, 0);
			font = font == null ? defaultFont : font;
			color = (color.R == 0 && color.G == 0 && color.B == 0 && color.A == 0) ? HtEngine.DefaultColor : color;
			//string id = null;
			//var align = TextAlign.Left;
			//var valign = VertAlign.Bottom;
			DrawTextDeco deco = DrawTextDeco.None;
			DrawTextEffect effect = DrawTextEffect.None;
			HtColor effectColor = HtEngine.DefaultColor;
			int effectAmount = 1;
			HtmlLink currentLink = null;
			bool prevIsWord = false;

			Stack<HtSpan> spanStack = new Stack<HtSpan>();	//top item is current span
			spanStack.Push(null);

			DeviceChunkLine currLine = null;
			DeviceChunkDrawText lastTextChunk = null;

			//for (int i = 0; i < htmlChunks.Count; i++)
			while (htmlChunks.MoveNext())
			{
				HtmlChunk htmlChunk = htmlChunks.Current;

				var word = htmlChunk as HtmlChunkWord;
				if (word != null)
				{
					if (currLine == null)
					{
						currLine = this.NewLine(null, viewportWidth, align, valign);
					}

					if (effect == DrawTextEffect.None)
					{
						lastTextChunk = AcquireDeviceChunkDrawText(
							spanStack.Peek(),
							id,
							word.Text,
							font,
							color,
							deco,
							lastTextChunk != null && lastTextChunk.Deco != deco,
							prevIsWord);
					}
					else
					{
						lastTextChunk = AcquireDeviceChunkDrawTextEffect(
							spanStack.Peek(),
							id,
							word.Text,
							font,
							color,
							deco,
							lastTextChunk != null && lastTextChunk.Deco != deco,
							effect,
							effectAmount,
							effectColor,
							prevIsWord);
					}

					if (currLine.AddChunk(lastTextChunk, prevIsWord))
					{
						if (currentLink != null && !this.Links.ContainsKey(lastTextChunk))
							this.Links.Add(lastTextChunk, currentLink);
					}
					else
					{

						//prevIsWord = true;	//why? AddChunk return false means a soft line break is needed
						//currLine.IsFull = true;
						string lastText = lastTextChunk.Text;
                        lastTextChunk.Dispose();
                        lastTextChunk = null;
                        bool decoStop = lastTextChunk != null && lastTextChunk.Deco != deco;
                        //Modify dfn.li                                               
                        //if (!currLine.IsFull)
                        {
                            var prevWidth = currLine.PrevChunkWidth();
                            var avaWidth = currLine.AvailWidth;
                            string sFix = "";
                            int nPos = 0;
                            for (nPos=0; nPos < lastText.Length; ++nPos )
                            {
                                char ch = lastText[nPos];
                                var len = font.Measure(ch.ToString()).Width;
                                if (prevWidth + len > viewportWidth)
                                {
                                    break;
                                }
                                else
                                {
                                    sFix = sFix + ch;
                                    prevWidth += len;
                                }
                            }
                            //补全上一行
                            if (!string.IsNullOrEmpty(sFix))
                            {
                                DeviceChunkDrawText tmpTextChunk;
                                if (effect == DrawTextEffect.None)
                                {
                                    tmpTextChunk = AcquireDeviceChunkDrawText(
                                        spanStack.Peek(),
                                        id,
                                        sFix,
                                        font,
                                        color,
                                        deco,
                                        lastTextChunk != null && lastTextChunk.Deco != deco,
                                        prevIsWord);
                                }
                                else
                                {
                                    tmpTextChunk = AcquireDeviceChunkDrawTextEffect(
                                        spanStack.Peek(),
                                        id,
                                        sFix,
                                        font,
                                        color,
                                        deco,
                                        lastTextChunk != null && lastTextChunk.Deco != deco,
                                        effect,
                                        effectAmount,
                                        effectColor,
                                        prevIsWord);
                                }
                                if (currLine.AddChunk(tmpTextChunk, prevIsWord, false))
                                {
                                    if (currentLink != null && !this.Links.ContainsKey(tmpTextChunk))
                                        this.Links.Add(tmpTextChunk, currentLink);
                                }
                                else
                                {
                                    tmpTextChunk.Dispose();
                                    tmpTextChunk = null;
                                }
                            }

                            lastText = lastText.Substring(nPos);
                            //currLine.IsFull = true; 
                        }
                        //Modify End
                        
						// find prefix ascii string.
						//string prefixAsciiText = null;
						int pos = 0;
						//for (pos = 0; pos < lastText.Length; ++pos) {
						//  char ch = lastText[pos];
						//  if (ch > 255 || ch == ' ') {
						//    prefixAsciiText = lastText.Substring(0, pos);
						//    break;
						//  }
						//}
						//if (prefixAsciiText != null) {
						//  DeviceChunkDrawText prefixAsciiTextChunk;
						//  if (effect == DrawTextEffect.None) {
						//    prefixAsciiTextChunk = AcquireDeviceChunkDrawText(
						//      id,
						//      prefixAsciiText,
						//      font,
						//      color,
						//      deco,
						//      decoStop,
						//      prevIsWord);
						//  } else {
						//    prefixAsciiTextChunk = AcquireDeviceChunkDrawTextEffect(
						//      id,
						//      prefixAsciiText,
						//      font,
						//      color,
						//      deco,
						//      decoStop,
						//      effect,
						//      effectAmount,
						//      effectColor,
						//      prevIsWord);
						//  }
						//  if (currLine.AddChunk(prefixAsciiTextChunk, prevIsWord)) {
						//    if (currentLink != null && !this.Links.ContainsKey(prefixAsciiTextChunk))
						//      this.Links.Add(prefixAsciiTextChunk, currentLink);
						//    lastText = lastText.Substring(pos);
						//    decoStop = false;
						//  }
						//}
						//// reset the pos.
						//pos = 0;

						// add multi-lines.
						int remainingWidth = viewportWidth;

						for (; pos < lastText.Length; )
						{
							char ch = lastText[pos];
							remainingWidth -= font.Measure(ch.ToString()).Width;
							if (remainingWidth < 0)
							{
								string tmpText = lastText.Substring(0, pos);
								DeviceChunkDrawText tmpTextChunk;
								if (effect == DrawTextEffect.None)
								{
									tmpTextChunk = AcquireDeviceChunkDrawText(
										spanStack.Peek(),
										id,
										tmpText,
										font,
										color,
										deco,
										decoStop,
										prevIsWord);
								}
								else
								{
									tmpTextChunk = AcquireDeviceChunkDrawTextEffect(
										spanStack.Peek(),
										id,
										tmpText,
										font,
										color,
										deco,
										decoStop,
										effect,
										effectAmount,
										effectColor,
										prevIsWord);
								}
								currLine = this.NewLine(currLine, viewportWidth, align, valign);
								if (currLine.AddChunk(tmpTextChunk, prevIsWord,false))
								{
									if (currentLink != null && !this.Links.ContainsKey(tmpTextChunk))
										this.Links.Add(tmpTextChunk, currentLink);
								}
								else
								{
									tmpTextChunk.Dispose();
									tmpTextChunk = null;
								}
								lastText = lastText.Substring(pos);
								pos = 0;
								remainingWidth = viewportWidth;
							}
							else
							{
								++pos;
							}
						}

						// add last line.
						if (!string.IsNullOrEmpty(lastText))
						{
							if (effect == DrawTextEffect.None)
							{
								lastTextChunk = AcquireDeviceChunkDrawText(
									spanStack.Peek(),
									id,
									lastText,
									font,
									color,
									deco,
									decoStop,
									prevIsWord);
							}
							else
							{
								lastTextChunk = AcquireDeviceChunkDrawTextEffect(
									spanStack.Peek(),
									id,
									lastText,
									font,
									color,
									deco,
									decoStop,
									effect,
									effectAmount,
									effectColor,
									prevIsWord);
							}

							currLine = this.NewLine(currLine, viewportWidth, align, valign);
							if (currLine.AddChunk(lastTextChunk, prevIsWord,false))
							{
								if (currentLink != null && !this.Links.ContainsKey(lastTextChunk))
									this.Links.Add(lastTextChunk, currentLink);
							}
							else
							{
								lastTextChunk.Dispose();
								lastTextChunk = null;
							}
						}
					}
					prevIsWord = true;
				}
				else
				{
					prevIsWord = false;
				}

				var tag = htmlChunk as HtmlChunkTag;
				if (tag != null)
				{
					switch (tag.Tag)
					{
						case "spin":
							if (tag.IsSingle)
							{
								// do nothing
							}
							else if (tag.IsClosing)
							{
								id = null;
								this.FinishLine(currLine, align, valign);
								return; // return control to parent
							}
							else
							{
								id = tag.GetAttr("id");
								ExctractAligns(tag, ref align, ref valign);
								var compiled = (DeviceChunkDrawCompiled)OP_DeviceChunkDrawCompiled.Acquire();
								compiled.Font = font;
								var scompiledWidth = tag.GetAttr("width") ?? "0";
								var compiledWidth = 0;
								if (!int.TryParse(scompiledWidth, out compiledWidth)) compiledWidth = 0;
								if (compiledWidth == 0)
								{
									compiledWidth = currLine == null ? viewportWidth : currLine.AvailWidth - font.WhiteSize;
								}
								if (compiledWidth > 0)
								{
									if (compiledWidth > viewportWidth) compiledWidth = viewportWidth;
									compiled.Parse(htmlChunks, compiledWidth, id, font, color, align, valign);
									compiled.MeasureSize();
									if (currLine == null)
									{
										currLine = this.NewLine(null, viewportWidth, align, valign);
									}

									if (!currLine.AddChunk(compiled, prevIsWord))
									{
										currLine.IsFull = true;
										currLine = this.NewLine(currLine, viewportWidth, align, valign);
										if (!currLine.AddChunk(compiled, prevIsWord))
										{
											HtEngine.Log(HtLogLevel.Error, "Could not fit spin into line. Word is too big: {0}", compiled);
											compiled.Dispose();
											compiled = null;
										}
									}
								}
								else
								{
									HtEngine.Log(HtLogLevel.Warning, "spin width is not given");
								}
							}
							break;
						case "effect":
							if (tag.IsSingle)
							{
								// do nothing
							}
							else if (tag.IsClosing)
							{
								effect = DrawTextEffect.None;
							}
							else
							{
								var name = tag.GetAttr("name") ?? "outline";
								switch (name)
								{
									case "shadow":
										effect = DrawTextEffect.Shadow;
										effectAmount = 1;
										effectColor = HtColor.RGBA(0, 0, 0, 80);
										break;
									case "outline":
										effect = DrawTextEffect.Outline;
										effectAmount = 1;
										effectColor = HtColor.RGBA(0xFF, 0xFF, 0xFF, 80);
										break;
								}
								var amount = tag.GetAttr("amount");
								if (amount != null)
								{
									if (!int.TryParse(amount, out effectAmount))
									{
										HtEngine.Log(HtLogLevel.Error, "Invalid numeric value: " + amount);
									}
								}
								var colors = tag.GetAttr("color");
								if (colors != null) effectColor = HtColor.Parse(colors);
							}
							break;
						case "u":
							if (tag.IsSingle)
							{
								// do nothing
							}
							else if (tag.IsClosing)
							{
								deco &= ~DrawTextDeco.Underline;
							}
							else
							{
								deco |= DrawTextDeco.Underline;
							}
							break;
						case "s":
						case "strike":
							if (tag.IsSingle)
							{
								// do nothing
							}
							else if (tag.IsClosing)
							{
								deco &= ~DrawTextDeco.Strike;
							}
							else
							{
								deco |= DrawTextDeco.Strike;
							}
							break;
						case "code":
							if (tag.IsSingle)
							{
								// do nothing
							}
							else if (tag.IsClosing)
							{
								font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
							}
							else
							{
								this.fontStack.Push(font);

								//const string fontName = "code";
								const string fontName = "default";
								int fontSize = font.Size;
								bool fontBold = font.Bold;
								bool fontItal = font.Italic;
								int spacingX = font.SpacingX;
								int spacingY = font.SpacingY;

								font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal, spacingX, spacingY);
							}
							break;

						case "b":
							if (tag.IsSingle)
							{
								// do nothing
							}
							else if (tag.IsClosing)
							{
								font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
							}
							else
							{
								this.fontStack.Push(font);

								string fontName = font.Face;
								int fontSize = font.Size;
								const bool fontBold = true;
								bool fontItal = font.Italic;
								int spacingX = font.SpacingX;
								int spacingY = font.SpacingY;

								font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal, spacingX, spacingY);
							}
							break;
						case "i":
							if (tag.IsSingle)
							{
								// do nothing
							}
							else if (tag.IsClosing)
							{
								font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
							}
							else
							{
								this.fontStack.Push(font);

								string fontName = font.Face;
								int fontSize = font.Size;
								bool fontBold = font.Bold;
								const bool fontItal = true;
								int spacingX = font.SpacingX;
								int spacingY = font.SpacingY;

								font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal, spacingX, spacingY);
							}
							break;
						case "a":
							if (tag.IsSingle)
							{
								// do nothing
							}
							else if (tag.IsClosing)
							{
								id = null;
								//if (this.colorStack.Count>0)		//不添加颜色。需要颜色时从外部指定
								//    color = this.colorStack.Pop();
								currentLink = null;
							}
							else
							{
								id = tag.GetAttr("id");
								currentLink = new HtmlLink();
								currentLink.linkID = linkID;
								currentLink.linkText = tag.GetAttr("href");
								++linkID;
								//this.colorStack.Push(color);		//不添加颜色。需要颜色时从外部指定
								//color = HtEngine.DefaultLinkColor;
							}
							break;

						case "font":
							if (tag.IsSingle)
							{
								// do nothing
							}
							else if (tag.IsClosing)
							{
								font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
								color = this.colorStack.Count > 0 ? this.colorStack.Pop() : HtEngine.DefaultColor;
							}
							else
							{
								this.fontStack.Push(font);
								this.colorStack.Push(color);

								string fontName = tag.GetAttr("face") ?? font.Face;
								string fontSizeS = tag.GetAttr("size");
								string fontSpaceXS = tag.GetAttr("spacing-x");
								string fontSpaceYS = tag.GetAttr("spacing-y");
								int fontSize;
								if (fontSizeS == null || !int.TryParse(fontSizeS, out fontSize)) fontSize = font.Size;
								int fontSpaceX;
								if (fontSpaceXS == null || !int.TryParse(fontSpaceXS, out fontSpaceX)) fontSpaceX = 0;
								int fontSpaceY;
								if (fontSpaceYS == null || !int.TryParse(fontSpaceYS, out fontSpaceY)) fontSpaceY = 0;
								bool fontBold = font.Bold;
								bool fontItal = font.Italic;

								font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal, fontSpaceX, fontSpaceY);

								color = HtColor.Parse(tag.GetAttr("color"), color);
							}
							break;
						case "br":
							currLine = this.NewLine(currLine, viewportWidth, align, valign);
							currLine.Height = font.LineSpacing;
							break;
						case "img":
							if (tag.IsClosing)
							{
								// ignore closing tags
							}
							else
							{
								var src = tag.GetAttr("src");
								var widthS = tag.GetAttr("width");
								var heightS = tag.GetAttr("height");
								var fpsS = tag.GetAttr("fps");
								var imgId = tag.GetAttr("id");
                                var snapS = tag.GetAttr("snap");

                                int w, h, fps;
                                bool snap;//true : 原像素,false:进行缩放
								if (widthS == null || !int.TryParse(widthS, out w)) w = -1;
								if (heightS == null || !int.TryParse(heightS, out h)) h = -1;
								if (fpsS == null || !int.TryParse(fpsS, out fps)) fps = -1;
                                if (snapS == null || !bool.TryParse(snapS, out snap)) snap = true;
								//var img = HtEngine.Device.LoadImage(src, fps);
                                var img = HtEngine.Device.LoadImageEx(src, fps, snap, w, h);
								if (w < 0) w = img.Width;
								if (h < 0) h = img.Height;
								var dChunk = (DeviceChunkDrawImage)OP_DeviceChunkDrawImage.Acquire();
								if (currLine == null)
									currLine = this.NewLine(null, viewportWidth, align, valign);
								dChunk.Image = img;
                                dChunk.Rect.Width = snap ? img.Width : w;
								dChunk.Rect.Height = snap ? img.Height : h;
								dChunk.Font = font; // for whitespace measure
								dChunk.Id = imgId;
								//HtEngine.Log(HtLogLevel.Debug, "Adding image w={0} h={1}",dChunk.Width,dChunk.Height);

								if (currLine.AddChunk(dChunk, prevIsWord))
								{
									if (currentLink != null && !this.Links.ContainsKey(dChunk))
										this.Links.Add(dChunk, currentLink);
								}
								else
								{
									currLine.IsFull = true;
									currLine = this.NewLine(currLine, viewportWidth, align, valign);
									if (currLine.AddChunk(dChunk, prevIsWord))
									{
										if (currentLink != null && !this.Links.ContainsKey(dChunk))
											this.Links.Add(dChunk, currentLink);
									}
									else
									{
										HtEngine.Log(HtLogLevel.Error, "Could not fit image into line. Image is too big: {0}", dChunk);
										dChunk.Dispose();
										dChunk = null;
									}
								}
							}
							break;
						case "gameobj":
							if (tag.IsClosing)
							{
								// ignore closing tags
							}
							else
							{
								var command = tag.GetAttr("command");
								var boxcollider = tag.GetAttr("boxcollider");
								var componentname = tag.GetAttr("componentname");
								var param = tag.GetAttr("param");
								var width = tag.GetAttr("width");
								var height = tag.GetAttr("height");
								var objid = tag.GetAttr("id");
								int w, h;
								bool b;
								if (width == null || !int.TryParse(width, out w)) w = 1;
								if (height == null || !int.TryParse(height, out h)) h = 1;
								if (boxcollider == null || !bool.TryParse(boxcollider, out b)) b = false;

								var dChunk = (DeviceChunkDrawGameObject)OP_DeviceChunkDrawGameObject.Acquire();
								if (currLine == null)
									currLine = this.NewLine(null, viewportWidth, align, valign);
								var go = new HTMLEngine.NGUI.NGUIGameObject(command, b, componentname, param);
								dChunk.gameobject = go;
								dChunk.Rect.Width = w;
								dChunk.Rect.Height = h;
								dChunk.Font = font; // for whitespace measure
								dChunk.Id = objid;
								//HtEngine.Log(HtLogLevel.Debug, "Adding image w={0} h={1}",dChunk.Width,dChunk.Height);

								if (currLine.AddChunk(dChunk, prevIsWord))
								{
									if (currentLink != null && !this.Links.ContainsKey(dChunk))
										this.Links.Add(dChunk, currentLink);
								}
								else
								{
									currLine.IsFull = true;
									currLine = this.NewLine(currLine, viewportWidth, align, valign);
									if (currLine.AddChunk(dChunk, prevIsWord))
									{
										if (currentLink != null && !this.Links.ContainsKey(dChunk))
											this.Links.Add(dChunk, currentLink);
									}
									else
									{
										HtEngine.Log(HtLogLevel.Error, "Could not fit gameobj into line. gameobj is too big: {0}", dChunk);
										dChunk.Dispose();
										dChunk = null;
									}
								}
							}
							break;
						case "p":
							if (tag.IsClosing)
							{
								id = null;
							}
							else
							{
								id = tag.GetAttr("id");
								currLine = this.NewLine(currLine, viewportWidth, align, valign);

								ExctractAligns(tag, ref align, ref valign);
							}

							break;
						case "span":
							if (tag.IsClosing)
							{
								spanStack.Pop();
								id = null;
							}
							else
							{
								HtSpan currentSpan = spanStack.Peek();
								HtSpan newSpan = new HtSpan(currentSpan, tag.GetAllAttributes());
								spanStack.Push(newSpan);

								id = tag.GetAttr("id");
								//currLine = this.NewLine(currLine, viewportWidth, align, valign);

								ExctractAligns(tag, ref align, ref valign);
							}

							break;
						default:
							HtEngine.Log(HtLogLevel.Error, "Unsupported html tag {0}", tag);
							break;
					}
				}
			}

			// align last line
			this.FinishLine(currLine, align, valign);
		}
 internal void Compile(IEnumerator <HtmlChunk> source, int width, TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
 {
     this.d.Clear();
     this.CompiledWidth = width;
     this.d.Parse(source, width, align, valign);
     this.UpdateHeight();
 }
Beispiel #29
0
 /// <summary>
 /// Align chunks verticaly
 /// </summary>
 /// <param name="align"></param>
 public void VertAlign(VertAlign align)
 {
     switch (align)
     {
         case Core.VertAlign.Top:
             for (int i = 0; i < list.Count; i++)
             {
                 var chunk = list[i];
                 chunk.Rect.Y = Y;
             }
             break;
         case Core.VertAlign.Middle:
             for (int i = 0; i < list.Count; i++)
             {
                 var chunk = list[i];
                 chunk.Rect.Y = Y + Height / 2 - chunk.Rect.Height / 2;
             }
             break;
         case Core.VertAlign.Bottom:
             for (int i = 0; i < list.Count; i++)
             {
                 var chunk = list[i];
                 chunk.Rect.Y = Y + Height - chunk.Rect.Height;
             }
             break;
     }
 }
Beispiel #30
0
 public void Parse(IEnumerator <HtmlChunk> source, int width, string id = null, HtFont font = null, HtColor color = default(HtColor), TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
 {
     compiled.Compile(source, width, id, font, color, align, valign);
     offsetApplied = false;
 }
Beispiel #31
0
        static void ExctractAligns(HtmlChunkTag tag, ref TextAlign align, ref VertAlign valign)
        {
            var tmp = tag.GetAttr("ALIGN");

            if (tmp != null)
            {
                switch (tmp.ToUpperInvariant())
                {
                case "CENTER":
                    align = TextAlign.Center;
                    break;

                case "JUSTIFY":
                    align = TextAlign.Justify;
                    break;

                case "RIGHT":
                    align = TextAlign.Right;
                    break;

                case "LEFT":
                    align = TextAlign.Left;
                    break;

                default:
                    HtEngine.Log(HtLogLevel.Warning, "Invalid attribute align: '{0}'", tmp);
                    align = TextAlign.Left;
                    break;
                }
            }
            else
            {
                //align = TextAlign.Left;
            }
            tmp = tag.GetAttr("VALIGN");
            if (tmp != null)
            {
                switch (tmp.ToUpperInvariant())
                {
                case "MIDDLE":
                    valign = VertAlign.Middle;
                    break;

                case "TOP":
                    valign = VertAlign.Top;
                    break;

                case "BOTTOM":
                    valign = VertAlign.Bottom;
                    break;

                default:
                    HtEngine.Log(HtLogLevel.Warning, "Invalid attribute valign: '{0}'", tmp);
                    valign = VertAlign.Bottom;
                    break;
                }
            }
            else
            {
                //valign = VertAlign.Bottom;
            }
        }
Beispiel #32
0
 internal void Compile(IEnumerator <HtmlChunk> source, int width, string id = null, HtFont font = null, HtColor color = default(HtColor), TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
 {
     this.d.Clear();
     this.CompiledWidth = width;
     this.d.Parse(source, width, id, font, color, align, valign);
     this.MergeSameTextChunks();
     this.UpdateHeight();
 }
Beispiel #33
0
        public void Parse(IEnumerator <HtmlChunk> htmlChunks, int viewportWidth, TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
        {
            this.Clear();
            var defaultFont = HtEngine.Device.LoadFont(HtEngine.DefaultFontFace, HtEngine.DefaultFontSize, false, false);
            var font        = defaultFont;
            var color       = HtEngine.DefaultColor;
            //var align = TextAlign.Left;
            //var valign = VertAlign.Bottom;
            DrawTextDeco   deco         = DrawTextDeco.None;
            DrawTextEffect effect       = DrawTextEffect.None;
            HtColor        effectColor  = HtEngine.DefaultColor;
            int            effectAmount = 1;
            string         currentLink  = null;


            DeviceChunkLine     currLine      = null;
            DeviceChunkDrawText lastTextChunk = null;

            //for (int i = 0; i < htmlChunks.Count; i++)
            while (htmlChunks.MoveNext())
            {
                HtmlChunk htmlChunk = htmlChunks.Current;

                var word = htmlChunk as HtmlChunkWord;
                if (word != null)
                {
                    if (currLine == null)
                    {
                        currLine = this.NewLine(null, viewportWidth, align, valign);
                    }

                    if (effect == DrawTextEffect.None)
                    {
                        var textChunk = OP <DeviceChunkDrawText> .Acquire();

                        textChunk.Text  = word.Text;
                        textChunk.Font  = font;
                        textChunk.Color = color;
                        textChunk.Deco  = deco;
                        if (lastTextChunk != null && lastTextChunk.Deco != deco)
                        {
                            lastTextChunk.DecoStop = true;
                        }
                        textChunk.MeasureSize();
                        lastTextChunk = textChunk;
                    }
                    else
                    {
                        var textChunk = OP <DeviceChunkDrawTextEffect> .Acquire();

                        textChunk.Text  = word.Text;
                        textChunk.Font  = font;
                        textChunk.Color = color;
                        textChunk.Deco  = deco;
                        if (lastTextChunk != null && lastTextChunk.Deco != deco)
                        {
                            lastTextChunk.DecoStop = true;
                        }
                        textChunk.Effect       = effect;
                        textChunk.EffectAmount = effectAmount;
                        textChunk.EffectColor  = effectColor;
                        textChunk.MeasureSize();
                        lastTextChunk = textChunk;
                    }

                    if (currentLink != null)
                    {
                        this.Links.Add(new KeyValuePair <DeviceChunk, string>(lastTextChunk, currentLink));
                    }
                    if (!currLine.AddChunk(lastTextChunk))
                    {
                        currLine.IsFull = true;
                        currLine        = this.NewLine(currLine, viewportWidth, align, valign);
                        if (!currLine.AddChunk(lastTextChunk))
                        {
                            HtEngine.Log(HtLogLevel.Error, "Could not fit word into line. Word is too big: {0}", lastTextChunk);
                            lastTextChunk.Dispose();
                            lastTextChunk = null;
                        }
                    }
                }

                var tag = htmlChunk as HtmlChunkTag;
                if (tag != null)
                {
                    switch (tag.Tag)
                    {
                    case "div":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            this.FinishLine(currLine, align, valign);
                            return;     // return control to parent
                        }
                        else
                        {
                            ExctractAligns(tag, ref align, ref valign);
                            var compiled = OP <DeviceChunkDrawCompiled> .Acquire();

                            compiled.Font = font;
                            var scompiledWidth = tag.GetAttr("width") ?? "0";
                            var compiledWidth  = 0;
                            if (!int.TryParse(scompiledWidth, out compiledWidth))
                            {
                                compiledWidth = 0;
                            }
                            if (compiledWidth == 0)
                            {
                                compiledWidth = currLine == null ? viewportWidth : currLine.AvailWidth - font.WhiteSize;
                            }
                            if (compiledWidth > 0)
                            {
                                compiled.Parse(htmlChunks, compiledWidth, align, valign);
                                compiled.MeasureSize();
                                if (currLine == null)
                                {
                                    currLine = this.NewLine(null, viewportWidth, align, valign);
                                }

                                if (!currLine.AddChunk(compiled))
                                {
                                    currLine.IsFull = true;
                                    currLine        = this.NewLine(currLine, viewportWidth, align, valign);
                                    if (!currLine.AddChunk(compiled))
                                    {
                                        HtEngine.Log(HtLogLevel.Error, "Could not fit div into line. Word is too big: {0}", lastTextChunk);
                                        compiled.Dispose();
                                        compiled = null;
                                    }
                                }
                            }
                            else
                            {
                                HtEngine.Log(HtLogLevel.Warning, "div width is not given");
                            }
                        }
                        break;

                    case "effect":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            effect = DrawTextEffect.None;
                        }
                        else
                        {
                            var name = tag.GetAttr("name") ?? "outline";
                            switch (name)
                            {
                            case "shadow":
                                effect       = DrawTextEffect.Shadow;
                                effectAmount = 1;
                                effectColor  = HtColor.RGBA(0, 0, 0, 80);
                                break;

                            case "outline":
                                effect       = DrawTextEffect.Outline;
                                effectAmount = 1;
                                effectColor  = HtColor.RGBA(0xFF, 0xFF, 0xFF, 80);
                                break;
                            }
                            var amount = tag.GetAttr("amount");
                            if (amount != null)
                            {
                                if (!int.TryParse(amount, out effectAmount))
                                {
                                    HtEngine.Log(HtLogLevel.Error, "Invalid numeric value: " + amount);
                                }
                            }
                            var colors = tag.GetAttr("color");
                            if (colors != null)
                            {
                                effectColor = HtColor.Parse(colors);
                            }
                        }
                        break;

                    case "u":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            deco &= ~DrawTextDeco.Underline;
                        }
                        else
                        {
                            deco |= DrawTextDeco.Underline;
                        }
                        break;

                    case "s":
                    case "strike":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            deco &= ~DrawTextDeco.Strike;
                        }
                        else
                        {
                            deco |= DrawTextDeco.Strike;
                        }
                        break;

                    case "code":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                        }
                        else
                        {
                            this.fontStack.Push(font);

                            const string fontName = "code";
                            int          fontSize = font.Size;
                            bool         fontBold = font.Bold;
                            bool         fontItal = font.Italic;

                            font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);
                        }
                        break;

                    case "b":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                        }
                        else
                        {
                            this.fontStack.Push(font);

                            string     fontName = font.Face;
                            int        fontSize = font.Size;
                            const bool fontBold = true;
                            bool       fontItal = font.Italic;

                            font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);
                        }
                        break;

                    case "i":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            font = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                        }
                        else
                        {
                            this.fontStack.Push(font);

                            string     fontName = font.Face;
                            int        fontSize = font.Size;
                            bool       fontBold = font.Bold;
                            const bool fontItal = true;

                            font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);
                        }
                        break;

                    case "a":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            if (this.colorStack.Count > 0)
                            {
                                color = this.colorStack.Pop();
                            }
                            currentLink = null;
                        }
                        else
                        {
                            currentLink = tag.GetAttr("href");
                            this.colorStack.Push(color);
                            color = HtEngine.DefaultLinkColor;
                        }
                        break;

                    case "font":
                        if (tag.IsSingle)
                        {
                            // do nothing
                        }
                        else if (tag.IsClosing)
                        {
                            font  = this.fontStack.Count > 0 ? this.fontStack.Pop() : defaultFont;
                            color = this.colorStack.Count > 0 ? this.colorStack.Pop() : HtEngine.DefaultColor;
                        }
                        else
                        {
                            this.fontStack.Push(font);
                            this.colorStack.Push(color);

                            string fontName  = tag.GetAttr("face") ?? font.Face;
                            string fontSizeS = tag.GetAttr("size");
                            int    fontSize;
                            if (fontSizeS == null || !int.TryParse(fontSizeS, out fontSize))
                            {
                                fontSize = font.Size;
                            }
                            bool fontBold = font.Bold;
                            bool fontItal = font.Italic;

                            font = HtEngine.Device.LoadFont(fontName, fontSize, fontBold, fontItal);

                            color = HtColor.Parse(tag.GetAttr("color"), color);
                        }
                        break;

                    case "br":
                        currLine        = this.NewLine(currLine, viewportWidth, align, valign);
                        currLine.Height = font.LineSpacing;
                        break;

                    case "img":
                        if (tag.IsClosing)
                        {
                            // ignore closing tags
                        }
                        else
                        {
                            var src = tag.GetAttr("src");
                            var widthS = tag.GetAttr("width");
                            var heightS = tag.GetAttr("height");
                            int w, h;
                            if (widthS == null || !int.TryParse(widthS, out w))
                            {
                                w = -1;
                            }
                            if (heightS == null || !int.TryParse(heightS, out h))
                            {
                                h = -1;
                            }
                            var img = HtEngine.Device.LoadImage(src);
                            if (w < 0)
                            {
                                w = img.Width;
                            }
                            if (h < 0)
                            {
                                h = img.Height;
                            }
                            var dChunk = OP <DeviceChunkDrawImage> .Acquire();

                            if (currLine == null)
                            {
                                currLine = this.NewLine(null, viewportWidth, align, valign);
                            }
                            dChunk.Image       = img;
                            dChunk.Rect.Width  = w;
                            dChunk.Rect.Height = h;
                            dChunk.Font        = font; // for whitespace measure
                            //HtEngine.Log(HtLogLevel.Debug, "Adding image w={0} h={1}",dChunk.Width,dChunk.Height);
                            if (currentLink != null)
                            {
                                this.Links.Add(new KeyValuePair <DeviceChunk, string>(dChunk, currentLink));
                            }
                            if (!currLine.AddChunk(dChunk))
                            {
                                currLine.IsFull = true;
                                currLine        = this.NewLine(currLine, viewportWidth, align, valign);
                                if (!currLine.AddChunk(dChunk))
                                {
                                    HtEngine.Log(HtLogLevel.Error, "Could not fit image into line. Image is too big: {0}", dChunk);
                                    dChunk.Dispose();
                                }
                            }
                        }
                        break;

                    case "p":
                        if (tag.IsClosing)
                        {
                            // ignore closing tags
                        }
                        else
                        {
                            currLine = this.NewLine(currLine, viewportWidth, align, valign);

                            ExctractAligns(tag, ref align, ref valign);
                        }

                        break;

                    default:
                        HtEngine.Log(HtLogLevel.Error, "Unsupported html tag {0}", tag);
                        break;
                    }
                }
            }

            // align last line
            this.FinishLine(currLine, align, valign);
        }
 public void Parse(IEnumerator<HtmlChunk> source, int width, TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
 {
     compiled.Compile(source, width, align, valign);
     offsetApplied = false;
 }
Beispiel #35
0
 private void HTMLGetStyle(FastString style, Font Font, Color TextColor, Color FillColor, HorzAlign HAlign, VertAlign VAlign,
                           Border Border, Padding Padding, bool RTL, bool wordWrap, float LineHeight, float ParagraphOffset)
 {
     HTMLFontStyle(style, Font, LineHeight);
     style.Append("color:").Append(ExportUtils.HTMLColor(TextColor)).Append(";");
     style.Append("background-color:");
     style.Append(FillColor.A == 0 ? "transparent" : ExportUtils.HTMLColor(FillColor)).Append(";");
     HTMLAlign(style, HAlign, VAlign, wordWrap);
     HTMLBorder(style, Border);
     HTMLPadding(style, Padding, ParagraphOffset);
     HTMLRtl(style, RTL);
     style.AppendLine("}");
 }
Beispiel #36
0
        private void DrawMajorTicks(FRPaintEventArgs e)
        {
            center    = (Parent as RadialGauge).Center;
            stepValue = (Parent.Maximum - Parent.Minimum) / (MajorTicks.Count - 1);
            if (RadialUtils.IsQuadrant(Parent))
            {
                stepValue *= 2;
            }

            avrValue = Parent.Minimum + (Parent.Maximum - Parent.Minimum) / 2;

            bool   isRightPart = true;
            bool   isLeftPart  = false;
            PointF txtPoint;

            Graphics g     = e.Graphics;
            Pen      pen   = e.Cache.GetPen(MajorTicks.Color, MajorTicks.Width * e.ScaleX, DashStyle.Solid);
            Brush    brush = TextFill.CreateBrush(new RectangleF(Parent.AbsLeft * e.ScaleX, Parent.AbsTop * e.ScaleY,
                                                                 Parent.Width * e.ScaleX, Parent.Height * e.ScaleY), e.ScaleX, e.ScaleY);

            sideTicksCount    = (MajorTicks.Count - 1) / 2;
            MajorTicks.Length = width / 12;

            SizeF maxTxt       = RadialUtils.GetStringSize(e, Parent, Font, Parent.Maximum.ToString());
            SizeF minTxt       = RadialUtils.GetStringSize(e, Parent, Font, Parent.Minimum.ToString());
            float maxTxtOffset = maxTxt.Height > maxTxt.Width ? maxTxt.Height : maxTxt.Width;
            float minTxtOffset = minTxt.Height > minTxt.Width ? minTxt.Height : minTxt.Width;

            majorTicksOffset = maxTxtOffset > minTxtOffset ? maxTxtOffset : minTxtOffset;

            PointF[] tick0 = new PointF[2];
            avrTick = new PointF(left + width / 2, top + majorTicksOffset);
            //first tick
            tick0[0] = avrTick;
            tick0[1] = new PointF(tick0[0].X, tick0[0].Y + MajorTicks.Length);

            double    angle      = 0;
            HorAlign  horAlign   = HorAlign.Middle;
            VertAlign vertAlign  = VertAlign.Bottom;
            double    startValue = avrValue;

            if (RadialUtils.IsSemicircle(Parent))
            {
                drawRight = true;
                drawLeft  = true;
                if (RadialUtils.IsBottom(Parent))
                {
                    angle       = 180 * RadialGauge.Radians;
                    horAlign    = HorAlign.Middle;
                    vertAlign   = VertAlign.Top;
                    majorStep  *= -1;
                    isRightPart = true;
                    isLeftPart  = false;
                }
                else if (RadialUtils.IsLeft(Parent))
                {
                    angle       = -90 * RadialGauge.Radians;
                    horAlign    = HorAlign.Right;
                    vertAlign   = VertAlign.Middle;
                    isRightPart = false;
                    isLeftPart  = false;
                }
                else if (RadialUtils.IsRight(Parent))
                {
                    angle       = 90 * RadialGauge.Radians;
                    horAlign    = HorAlign.Left;
                    vertAlign   = VertAlign.Middle;
                    majorStep  *= -1;
                    isRightPart = true; //false
                    isLeftPart  = true; // false
                }
            }


            else if (RadialUtils.IsQuadrant(Parent))
            {
                if (RadialUtils.IsTop(Parent) && RadialUtils.IsLeft(Parent))
                {
                    startValue = Parent.Maximum;
                    //angle = 180 * RadialGauge.Radians;
                    horAlign  = HorAlign.Middle;
                    vertAlign = VertAlign.Bottom;
                    //majorStep *= -1;
                    //isRightPart = true;
                    //isLeftPart = false;
                    drawRight = false;
                    drawLeft  = true;

                    isRightPart = false;
                    isLeftPart  = false;
                }
                else if (RadialUtils.IsBottom(Parent) && RadialUtils.IsLeft(Parent))
                {
                    startValue = Parent.Minimum;
                    angle      = 180 * RadialGauge.Radians;
                    horAlign   = HorAlign.Middle;
                    vertAlign  = VertAlign.Top;
                    drawRight  = true;
                    drawLeft   = false;

                    isRightPart = false;
                    isLeftPart  = false;
                }
                else if (RadialUtils.IsTop(Parent) && RadialUtils.IsRight(Parent))
                {
                    stepValue *= -1;
                    startValue = Parent.Maximum;
                    angle      = 0;
                    horAlign   = HorAlign.Middle;
                    vertAlign  = VertAlign.Bottom;
                    drawRight  = true;
                    drawLeft   = false;

                    isRightPart = true;
                    isLeftPart  = true;
                }
                else if (RadialUtils.IsBottom(Parent) && RadialUtils.IsRight(Parent))
                {
                    stepValue *= -1;
                    startValue = Parent.Minimum;
                    angle      = 180 * RadialGauge.Radians;
                    horAlign   = HorAlign.Middle;
                    vertAlign  = VertAlign.Top;
                    drawRight  = false;
                    drawLeft   = true;

                    isRightPart = true;
                    isLeftPart  = true;
                }
            }
            else
            {
                drawRight = true;
                drawLeft  = true;
            }

            tick0 = RadialUtils.RotateVector(tick0, angle, center);

            g.DrawLine(pen, tick0[0].X, tick0[0].Y, tick0[1].X, tick0[1].Y);
            string text = startValue.ToString();

            DrawText(e, text, brush, tick0[0].X, tick0[0].Y, horAlign, vertAlign);

            //rest of ticks
            PointF[] tick = new PointF[2];
            angle = majorStep * RadialGauge.Radians;

            for (int i = 0; i < sideTicksCount; i++)
            {
                //right side
                if (drawRight)
                {
                    tick = RadialUtils.RotateVector(tick0, angle, center);
                    g.DrawLine(pen, tick[0].X, tick[0].Y, tick[1].X, tick[1].Y);
                    text = Convert.ToString(Math.Round(startValue + stepValue * (i + 1)));

                    if (i == sideTicksCount / 2)
                    {
                        if (RadialUtils.IsSemicircle(Parent) || RadialUtils.IsQuadrant(Parent))
                        {
                            if (RadialUtils.IsLeft(Parent) && RadialUtils.IsTop(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsLeft(Parent) && RadialUtils.IsBottom(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsRight(Parent) && RadialUtils.IsTop(Parent))
                            {
                                horAlign  = HorAlign.Left;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsLeft(Parent))
                            {
                                horAlign  = HorAlign.Middle;
                                vertAlign = VertAlign.Bottom;
                            }
                            else if (RadialUtils.IsRight(Parent))
                            {
                                horAlign  = HorAlign.Middle;
                                vertAlign = VertAlign.Bottom;
                            }
                            else
                            {
                                horAlign  = HorAlign.Left;
                                vertAlign = VertAlign.Middle;
                            }
                        }
                        else
                        {
                            horAlign  = HorAlign.Left;
                            vertAlign = VertAlign.Middle;
                        }
                    }
                    else if (i < sideTicksCount / 2)
                    {
                        horAlign = HorAlign.Left;
                        if (RadialUtils.IsSemicircle(Parent) || RadialUtils.IsQuadrant(Parent))
                        {
                            if (RadialUtils.IsLeft(Parent) && RadialUtils.IsTop(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Middle;
                            }
                            if (RadialUtils.IsLeft(Parent) && RadialUtils.IsBottom(Parent))
                            {
                                vertAlign = VertAlign.Top;
                                horAlign  = HorAlign.Right;
                            }
                            else if (RadialUtils.IsBottom(Parent))
                            {
                                vertAlign = VertAlign.Top;
                            }
                            else if (RadialUtils.IsLeft(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Bottom;
                            }
                            else if (RadialUtils.IsRight(Parent))
                            {
                                horAlign  = HorAlign.Left;
                                vertAlign = VertAlign.Bottom;
                            }
                        }
                        else
                        {
                            vertAlign = VertAlign.Bottom;
                        }
                    }
                    else
                    {
                        horAlign  = HorAlign.Left;
                        vertAlign = VertAlign.Top;
                    }
                    txtPoint = GetTextPoint(tick, -1 * e.ScaleX, isNegative(i, true), isRightPart);
                    DrawText(e, text, brush, txtPoint.X, txtPoint.Y, horAlign, vertAlign);
                }

                if (drawLeft)
                {
                    //left side
                    angle *= -1;
                    tick   = RadialUtils.RotateVector(tick0, angle, center);
                    g.DrawLine(pen, tick[0].X, tick[0].Y, tick[1].X, tick[1].Y);
                    text = Convert.ToString(Math.Round(startValue - stepValue * (i + 1)));

                    if (i == sideTicksCount / 2)
                    {
                        if (RadialUtils.IsSemicircle(Parent) || RadialUtils.IsQuadrant(Parent))
                        {
                            if ((RadialUtils.IsTop(Parent) || RadialUtils.IsBottom(Parent)) && RadialUtils.IsSemicircle(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsLeft(Parent) && RadialUtils.IsTop(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsRight(Parent) && RadialUtils.IsBottom(Parent))
                            {
                                horAlign  = HorAlign.Left;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsLeft(Parent))
                            {
                                horAlign  = HorAlign.Middle;
                                vertAlign = VertAlign.Top;
                            }
                            else if (RadialUtils.IsRight(Parent))
                            {
                                horAlign  = HorAlign.Middle;
                                vertAlign = VertAlign.Top;
                            }
                        }
                        else
                        {
                            horAlign  = HorAlign.Right;
                            vertAlign = VertAlign.Middle;
                        }
                    }
                    else if (i < sideTicksCount / 2)
                    {
                        horAlign = HorAlign.Right;

                        if (RadialUtils.IsSemicircle(Parent) || RadialUtils.IsQuadrant(Parent))
                        {
                            if (RadialUtils.IsRight(Parent) && RadialUtils.IsBottom(Parent))
                            {
                                vertAlign = VertAlign.Top;
                                horAlign  = HorAlign.Left;
                            }
                            else if (RadialUtils.IsTop(Parent) && RadialUtils.IsLeft(Parent))
                            {
                                vertAlign = VertAlign.Bottom;
                                horAlign  = HorAlign.Right;
                            }
                            else if (RadialUtils.IsBottom(Parent))
                            {
                                vertAlign = VertAlign.Top;
                            }
                            else if (RadialUtils.IsLeft(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Top;
                            }
                            else if (RadialUtils.IsRight(Parent))
                            {
                                horAlign  = HorAlign.Left;
                                vertAlign = VertAlign.Top;
                            }
                        }
                        else
                        {
                            vertAlign = VertAlign.Bottom;
                        }
                    }
                    else
                    {
                        horAlign  = HorAlign.Right;
                        vertAlign = VertAlign.Top;
                    }
                    txtPoint = GetTextPoint(tick, -1 * e.ScaleX, isNegative(i, false), isLeftPart);
                    DrawText(e, text, brush, txtPoint.X, txtPoint.Y, horAlign, vertAlign);
                    angle *= -1;
                }

                angle += majorStep * RadialGauge.Radians;
            }
        }
 public void Parse(IEnumerator <HtmlChunk> source, int width, TextAlign align = TextAlign.Left, VertAlign valign = VertAlign.Bottom)
 {
     compiled.Compile(source, width, align, valign);
     offsetApplied = false;
 }