Beispiel #1
0
        private void SetItemInternal(object parent, object item, double previewScale, int themeCategory)
        {
            m_parent           = parent;
            m_label            = item as ITextSymbol;
            m_point            = item as IPointSymbolization2D;
            m_area             = item as IAreaSymbolizationFill;
            m_comp             = item as ICompositeSymbolization;
            m_w2dsymbol        = item as Image;
            this.PreviewScale  = previewScale;
            this.ThemeCategory = themeCategory;

            if (item is IEnumerable <IStroke> )
            {
                m_line = new List <IStroke>((IEnumerable <IStroke>)item);
            }
            else
            {
                m_line = null;
            }
        }
Beispiel #2
0
        private void EditRuleStyle(RuleModel rule)
        {
            PointRuleModel     pr = rule as PointRuleModel;
            LineRuleModel      lr = rule as LineRuleModel;
            AreaRuleModel      ar = rule as AreaRuleModel;
            CompositeRuleModel cr = rule as CompositeRuleModel;

            UserControl uc = null;

            /*
             * if (m_owner.SelectedClass == null)
             * {
             *  MessageBox.Show(Strings.NoFeatureClassAssigned);
             *  return;
             * }*/
            var previewScale = 0.0;

            if (_parentScaleRange.MinScale.HasValue)
            {
                previewScale = _parentScaleRange.MinScale.Value;
            }
            ILayerStylePreviewable prev = new LayerStylePreviewable(_edSvc.EditedResourceID,
                                                                    previewScale,
                                                                    80,
                                                                    40,
                                                                    "PNG", //NOXLATE
                                                                    this.ThemeIndexOffest + rule.Index);

            //TODO: This is obviously a mess and could do with some future cleanup, but the idea here should be
            //easy to understand. Each primitive basic style (that's not a label) has 3 actions.
            // - Commit (When user clicks OK on dialog)
            // - Rollback (When user clicks Cancel on dialog)
            // - Edit Commit (When user invokes refresh)
            //Those that support GETLEGENDIMAGE-based previews will be passed an edit commit action. Invoking the
            //edit commit action will update the session-based layer with this edit-copy rule, allowing for the changes
            //to be reflected when we do the GETLEGENDIMAGE call
            //
            //Labels are exempt as those previews can be sufficiently simulated with System.Drawing API
            var             vl       = (IVectorLayerDefinition)_editedLayer.SubLayer;
            ClassDefinition clsDef   = GetLayerClass();
            Action          commit   = null;
            Action          rollback = null;

            if (pr != null)
            {
                var sym = pr.GetSymbolizationStyle();

                m_origPoint = sym;
                m_editPoint = (sym == null) ? null : (IPointSymbolization2D)sym.Clone();

                var pfse = new PointFeatureStyleEditor(_edSvc, clsDef, vl.ResourceId, pr.Style, prev);
                uc        = pfse;
                pfse.Item = m_editPoint;

                Action editCommit = () =>
                {
                    m_editPoint = pfse.Item;
                    pr.SetSymbolizationStyle(m_editPoint);
                };
                pfse.SetEditCommit(editCommit);
                commit = () =>
                {
                    pr.SetSymbolizationStyle(pfse.Item);
                    _edSvc.HasChanged();
                    UpdateRulePreviewAsync(pr);
                };
                rollback = () =>
                {
                    pr.SetSymbolizationStyle(m_origPoint);
                };
            }
            else if (lr != null)
            {
                var lineSym = lr.GetSymbolizationStyle();
                var strokes = lineSym.Strokes;
                m_origLine = strokes;
                m_editLine = (strokes == null) ? new List <IStroke>() : LayerElementCloningUtil.CloneStrokes(strokes);

                var lfse = new LineFeatureStyleEditor(_edSvc, clsDef, vl.ResourceId, _editedLayer, prev);
                uc        = lfse;
                lfse.Item = m_editLine;

                Action editCommit = () =>
                {
                    m_editLine = lfse.Item;
                    lineSym.SetStrokes(m_editLine);
                };
                lfse.SetEditCommit(editCommit);
                commit = () =>
                {
                    lineSym.SetStrokes(lfse.Item);
                    _edSvc.HasChanged();
                    UpdateRulePreviewAsync(lr);
                };
                rollback = () =>
                {
                    lineSym.SetStrokes(m_origLine);
                };
            }
            else if (ar != null)
            {
                var area = ar.GetSymbolizationStyle();

                m_origArea = area;
                m_editArea = (area == null) ? null : (IAreaSymbolizationFill)area.Clone();

                var afse = new AreaFeatureStyleEditor(_edSvc, clsDef, vl.ResourceId, prev);
                uc        = afse;
                afse.Item = m_editArea;

                Action editCommit = () =>
                {
                    m_editArea = afse.Item;
                    ar.SetSymbolizationStyle(m_editArea);
                };
                commit = () =>
                {
                    ar.SetSymbolizationStyle(afse.Item);
                    _edSvc.HasChanged();
                    UpdateRulePreviewAsync(ar);
                };
                rollback = () =>
                {
                    ar.SetSymbolizationStyle(m_origArea);
                };
                afse.SetEditCommit(editCommit);
            }
            else if (cr != null)
            {
                var diag = new SymbolInstancesDialog(_edSvc, cr.GetSymbolizationStyle(), GetLayerClass(), GetLayerProvider(), vl.ResourceId, prev);
                diag.ShowDialog();
                //HACK: Assume edits made
                _edSvc.HasChanged();
                UpdateRulePreviewAsync(cr);
                return;
            }

            if (uc != null)
            {
                EditorTemplateForm dlg = new EditorTemplateForm();
                dlg.ItemPanel.Controls.Add(uc);
                uc.Dock = DockStyle.Fill;
                dlg.RefreshSize();
                var res = dlg.ShowDialog(this);
                if (res == DialogResult.OK)
                {
                    if (commit != null)
                    {
                        commit.Invoke();
                    }

                    if (pr != null)
                    {
                        _edSvc.HasChanged();
                    }
                    else if (lr != null)
                    {
                        _edSvc.HasChanged();
                    }
                    else if (ar != null)
                    {
                        _edSvc.HasChanged();
                    }
                }
                else if (res == DialogResult.Cancel)
                {
                    if (rollback != null)
                    {
                        rollback.Invoke();
                    }
                }
            }
        }
Beispiel #3
0
        private void SetItemInternal(object parent, object item, double previewScale, int themeCategory)
        {
            m_parent = parent;
            m_label = item as ITextSymbol;
            m_point = item as IPointSymbolization2D;
            m_area = item as IAreaSymbolizationFill;
            m_comp = item as ICompositeSymbolization;
            m_w2dsymbol = item as Image;
            this.PreviewScale = previewScale;
            this.ThemeCategory = themeCategory;

            if (item is IEnumerable<IStroke>)
                m_line = new List<IStroke>((IEnumerable<IStroke>)item);
            else
                m_line = null;
        }
Beispiel #4
0
        private void EditButton_Click(object sender, EventArgs e)
        {
            UserControl uc = null;
            if (m_owner.SelectedClass == null)
            {
                MessageBox.Show(Strings.NoFeatureClassAssigned);
                return;
            }
            ILayerStylePreviewable prev = new LayerStylePreviewable(m_owner.EditorService.EditedResourceID,
                                                                    this.PreviewScale,
                                                                    80,
                                                                    40,
                                                                    "PNG", //NOXLATE
                                                                    this.ThemeCategory);

            //TODO: This is obviously a mess and could do with some future cleanup, but the idea here should be
            //easy to understand. Each primitive basic style (that's not a label) has 3 actions.
            // - Commit (When user clicks OK on dialog)
            // - Rollback (When user clicks Cancel on dialog)
            // - Edit Commit (When user invokes refresh)
            //Those that support GETLEGENDIMAGE-based previews will be passed an edit commit action. Invoking the
            //edit commit action will update the session-based layer with this edit-copy rule, allowing for the changes
            //to be reflected when we do the GETLEGENDIMAGE call
            //
            //Labels are exempt as those previews can be sufficiently simulated with System.Drawing API
            var factory = (ILayerElementFactory)m_owner.Editor.GetEditedResource();
            Action commit = null;
            Action rollback = null;
            if (isLabel)
            {
                m_origLabel = m_label;
                m_editLabel = (m_label == null) ? null : (ITextSymbol)m_label.Clone();

                uc = new FontStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId);
                ((FontStyleEditor)uc).Item = m_editLabel;
            }
            else if (isW2dSymbol)
            {
                m_origPoint = m_point;
                m_editPoint = (m_point == null) ? null : (IPointSymbolization2D)m_point.Clone();

                var pfse = new PointFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, m_w2dsymbol, prev);
                uc = pfse;
                pfse.Item = m_editPoint;

                Action editCommit = () =>
                {
                    //We need to update this boolean state
                    var w2d = pfse.W2DSymbolPreviewImage;
                    this.isPoint = (w2d == null);
                    this.isW2dSymbol = (w2d != null);

                    m_editPoint = pfse.Item;
                    ((IPointRule)m_parent).PointSymbolization2D = m_editPoint;

                    m_w2dsymbol = w2d;
                };
                pfse.SetEditCommit(editCommit);
                commit = () =>
                {
                    //We need to update this boolean state
                    var w2d = pfse.W2DSymbolPreviewImage;
                    this.isPoint = (w2d == null);
                    this.isW2dSymbol = (w2d != null);

                    m_point = pfse.Item;
                    ((IPointRule)m_parent).PointSymbolization2D = m_point;

                    m_w2dsymbol = w2d;
                };
                rollback = () =>
                {
                    ((IPointRule)m_parent).PointSymbolization2D = m_origPoint;
                };
            }
            else if (isPoint)
            {
                m_origPoint = m_point;
                m_editPoint = (m_point == null) ? null : (IPointSymbolization2D)m_point.Clone();

                var pfse = new PointFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, prev);
                uc = pfse;
                pfse.Item = m_editPoint;

                Action editCommit = () =>
                {
                    //We need to update this boolean state
                    var w2d = pfse.W2DSymbolPreviewImage;
                    this.isPoint = (w2d == null);
                    this.isW2dSymbol = (w2d != null);

                    m_editPoint = pfse.Item;
                    ((IPointRule)m_parent).PointSymbolization2D = m_editPoint;

                    m_w2dsymbol = w2d;
                };
                pfse.SetEditCommit(editCommit);
                commit = () =>
                {
                    //We need to update this boolean state
                    var w2d = pfse.W2DSymbolPreviewImage;
                    this.isPoint = (w2d == null);
                    this.isW2dSymbol = (w2d != null);

                    m_point = pfse.Item;
                    ((IPointRule)m_parent).PointSymbolization2D = m_point;

                    m_w2dsymbol = w2d;
                };
                rollback = () =>
                {
                    ((IPointRule)m_parent).PointSymbolization2D = m_origPoint;
                };
            }
            else if (isLine)
            {
                m_origLine = m_line;
                m_editLine = (m_line == null) ? new List<IStroke>() : LayerElementCloningUtil.CloneStrokes(m_line);

                var lfse = new LineFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, factory, prev);
                uc = lfse;
                lfse.Item = m_editLine;

                Action editCommit = () =>
                {
                    m_editLine = lfse.Item;
                    ((ILineRule)m_parent).SetStrokes(m_editLine);
                };
                lfse.SetEditCommit(editCommit);
                commit = () =>
                {
                    m_line = lfse.Item;
                    ((ILineRule)m_parent).SetStrokes(m_line);
                };
                rollback = () =>
                {
                    ((ILineRule)m_parent).SetStrokes(m_origLine);
                };
            }
            else if (isArea)
            {
                m_origArea = m_area;
                m_editArea = (m_area == null) ? null : (IAreaSymbolizationFill)m_area.Clone();

                var afse = new AreaFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, prev);
                uc = afse;
                afse.Item = m_editArea;

                Action editCommit = () =>
                {
                    m_editArea = afse.Item;
                    ((IAreaRule)m_parent).AreaSymbolization2D = m_editArea;
                };
                commit = () =>
                {
                    m_area = afse.Item;
                    ((IAreaRule)m_parent).AreaSymbolization2D = m_area;
                };
                rollback = () =>
                {
                    ((IAreaRule)m_parent).AreaSymbolization2D = m_origArea;
                };
                afse.SetEditCommit(editCommit);
            }
            else if (isComp)
            {
                var diag = new SymbolInstancesDialog(m_owner.Editor, m_comp, m_owner.SelectedClass, m_owner.GetFdoProvider(), m_owner.FeatureSourceId, prev);
                diag.ShowDialog();
                //HACK: Assume edits made
                Owner.RaiseResourceChanged();
                return;
            }

            if (uc != null)
            {
                EditorTemplateForm dlg = new EditorTemplateForm();
                dlg.ItemPanel.Controls.Add(uc);
                uc.Dock = DockStyle.Fill;
                dlg.RefreshSize();
                var res = dlg.ShowDialog(this);
                if (res == DialogResult.OK)
                {
                    if (commit != null)
                    {
                        commit.Invoke();
                    }

                    if (isLabel)
                    {
                        m_label = ((FontStyleEditor)uc).Item;
                        if (m_parent as IPointRule != null)
                            ((IPointRule)m_parent).Label = m_label;
                        else if (m_parent as ILineRule != null)
                            ((ILineRule)m_parent).Label = m_label;
                        else if (m_parent as IAreaRule != null)
                            ((IAreaRule)m_parent).Label = m_label;

                        if (ItemChanged != null)
                            ItemChanged(m_label, null);
                    }
                    else if (isPoint || isW2dSymbol)
                    {
                        if (ItemChanged != null)
                            ItemChanged(m_point, null);
                    }
                    else if (isLine)
                    {

                        if (ItemChanged != null)
                            ItemChanged(m_line, null);
                    }
                    else if (isArea)
                    {
                        if (ItemChanged != null)
                            ItemChanged(m_area, null);
                    }

                    this.Refresh();
                }
                else if (res == DialogResult.Cancel)
                {
                    if (rollback != null)
                        rollback.Invoke();
                }
            }
        }
Beispiel #5
0
 public void SetItem(IAreaRule parent, IAreaSymbolizationFill area, double previewScale, int themeCategory)
 {
     isArea = true;
     SetItemInternal(parent, area, previewScale, themeCategory);
 }
Beispiel #6
0
 public void SetItem(IAreaRule parent, IAreaSymbolizationFill area, double previewScale, int themeCategory)
 {
     isArea = true;
     SetItemInternal(parent, area, previewScale, themeCategory);
 }
Beispiel #7
0
        private void EditButton_Click(object sender, EventArgs e)
        {
            UserControl uc = null;

            if (m_owner.SelectedClass == null)
            {
                MessageBox.Show(Strings.NoFeatureClassAssigned);
                return;
            }
            ILayerStylePreviewable prev = new LayerStylePreviewable(m_owner.EditorService.EditedResourceID,
                                                                    this.PreviewScale,
                                                                    80,
                                                                    40,
                                                                    "PNG", //NOXLATE
                                                                    _themeOffset + this.ThemeCategory);

            //TODO: This is obviously a mess and could do with some future cleanup, but the idea here should be
            //easy to understand. Each primitive basic style (that's not a label) has 3 actions.
            // - Commit (When user clicks OK on dialog)
            // - Rollback (When user clicks Cancel on dialog)
            // - Edit Commit (When user invokes refresh)
            //Those that support GETLEGENDIMAGE-based previews will be passed an edit commit action. Invoking the
            //edit commit action will update the session-based layer with this edit-copy rule, allowing for the changes
            //to be reflected when we do the GETLEGENDIMAGE call
            //
            //Labels are exempt as those previews can be sufficiently simulated with System.Drawing API
            var    factory  = (ILayerElementFactory)m_owner.Editor.GetEditedResource();
            Action commit   = null;
            Action rollback = null;

            if (isLabel)
            {
                m_origLabel = m_label;
                m_editLabel = (m_label == null) ? null : (ITextSymbol)m_label.Clone();

                uc = new FontStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId);
                ((FontStyleEditor)uc).Item = m_editLabel;
            }
            else if (isW2dSymbol)
            {
                m_origPoint = m_point;
                m_editPoint = (m_point == null) ? null : (IPointSymbolization2D)m_point.Clone();

                var pfse = new PointFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, m_w2dsymbol, prev);
                uc        = pfse;
                pfse.Item = m_editPoint;

                Action editCommit = () =>
                {
                    //We need to update this boolean state
                    var w2d = pfse.W2DSymbolPreviewImage;
                    this.isPoint     = (w2d == null);
                    this.isW2dSymbol = (w2d != null);

                    m_editPoint = pfse.Item;
                    ((IPointRule)m_parent).PointSymbolization2D = m_editPoint;

                    m_w2dsymbol = w2d;
                };
                pfse.SetEditCommit(editCommit);
                commit = () =>
                {
                    //We need to update this boolean state
                    var w2d = pfse.W2DSymbolPreviewImage;
                    this.isPoint     = (w2d == null);
                    this.isW2dSymbol = (w2d != null);

                    m_point = pfse.Item;
                    ((IPointRule)m_parent).PointSymbolization2D = m_point;

                    m_w2dsymbol = w2d;
                };
                rollback = () =>
                {
                    ((IPointRule)m_parent).PointSymbolization2D = m_origPoint;
                };
            }
            else if (isPoint)
            {
                m_origPoint = m_point;
                m_editPoint = (m_point == null) ? null : (IPointSymbolization2D)m_point.Clone();

                var pfse = new PointFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, prev);
                uc        = pfse;
                pfse.Item = m_editPoint;

                Action editCommit = () =>
                {
                    //We need to update this boolean state
                    var w2d = pfse.W2DSymbolPreviewImage;
                    this.isPoint     = (w2d == null);
                    this.isW2dSymbol = (w2d != null);

                    m_editPoint = pfse.Item;
                    ((IPointRule)m_parent).PointSymbolization2D = m_editPoint;

                    m_w2dsymbol = w2d;
                };
                pfse.SetEditCommit(editCommit);
                commit = () =>
                {
                    //We need to update this boolean state
                    var w2d = pfse.W2DSymbolPreviewImage;
                    this.isPoint     = (w2d == null);
                    this.isW2dSymbol = (w2d != null);

                    m_point = pfse.Item;
                    ((IPointRule)m_parent).PointSymbolization2D = m_point;

                    m_w2dsymbol = w2d;
                };
                rollback = () =>
                {
                    ((IPointRule)m_parent).PointSymbolization2D = m_origPoint;
                };
            }
            else if (isLine)
            {
                m_origLine = m_line;
                m_editLine = (m_line == null) ? new List <IStroke>() : LayerElementCloningUtil.CloneStrokes(m_line);

                var lfse = new LineFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, factory, prev);
                uc        = lfse;
                lfse.Item = m_editLine;

                Action editCommit = () =>
                {
                    m_editLine = lfse.Item;
                    ((ILineRule)m_parent).SetStrokes(m_editLine);
                };
                lfse.SetEditCommit(editCommit);
                commit = () =>
                {
                    m_line = lfse.Item;
                    ((ILineRule)m_parent).SetStrokes(m_line);
                };
                rollback = () =>
                {
                    ((ILineRule)m_parent).SetStrokes(m_origLine);
                };
            }
            else if (isArea)
            {
                m_origArea = m_area;
                m_editArea = (m_area == null) ? null : (IAreaSymbolizationFill)m_area.Clone();

                var afse = new AreaFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, prev);
                uc        = afse;
                afse.Item = m_editArea;

                Action editCommit = () =>
                {
                    m_editArea = afse.Item;
                    ((IAreaRule)m_parent).AreaSymbolization2D = m_editArea;
                };
                commit = () =>
                {
                    m_area = afse.Item;
                    ((IAreaRule)m_parent).AreaSymbolization2D = m_area;
                };
                rollback = () =>
                {
                    ((IAreaRule)m_parent).AreaSymbolization2D = m_origArea;
                };
                afse.SetEditCommit(editCommit);
            }
            else if (isComp)
            {
                var diag = new SymbolInstancesDialog(m_owner.Editor, m_comp, m_owner.SelectedClass, m_owner.GetFdoProvider(), m_owner.FeatureSourceId, prev);
                diag.ShowDialog();
                //HACK: Assume edits made
                Owner.RaiseResourceChanged();
                return;
            }

            if (uc != null)
            {
                EditorTemplateForm dlg = new EditorTemplateForm();
                dlg.ItemPanel.Controls.Add(uc);
                uc.Dock = DockStyle.Fill;
                dlg.RefreshSize();
                var res = dlg.ShowDialog(this);
                if (res == DialogResult.OK)
                {
                    if (commit != null)
                    {
                        commit.Invoke();
                    }

                    if (isLabel)
                    {
                        m_label = ((FontStyleEditor)uc).Item;
                        if (m_parent as IPointRule != null)
                        {
                            ((IPointRule)m_parent).Label = m_label;
                        }
                        else if (m_parent as ILineRule != null)
                        {
                            ((ILineRule)m_parent).Label = m_label;
                        }
                        else if (m_parent as IAreaRule != null)
                        {
                            ((IAreaRule)m_parent).Label = m_label;
                        }

                        ItemChanged?.Invoke(m_label, null);
                    }
                    else if (isPoint || isW2dSymbol)
                    {
                        ItemChanged?.Invoke(m_point, null);
                    }
                    else if (isLine)
                    {
                        ItemChanged?.Invoke(m_line, null);
                    }
                    else if (isArea)
                    {
                        ItemChanged?.Invoke(m_area, null);
                    }

                    this.Refresh();
                }
                else if (res == DialogResult.Cancel)
                {
                    if (rollback != null)
                    {
                        rollback.Invoke();
                    }
                }
            }
        }
Beispiel #8
0
        public static void RenderPreviewArea(Graphics g, Rectangle size, IAreaSymbolizationFill item)
        {
            if (item == null)
            {
                RenderPreviewFont(g, size, null);
                return;
            }

            //Adjust, since painting always excludes top/right and includes left/bottom
            Rectangle size_adj = new Rectangle(size.X, size.Y, size.Width - 1, size.Height - 1);

            Point[] points = new Point[]
            {
                new Point(size_adj.Left, size_adj.Top),
                new Point(size_adj.Right, size_adj.Top),
                new Point(size_adj.Right, size_adj.Bottom),
                new Point(size_adj.Left, size_adj.Bottom),
                new Point(size_adj.Left, size_adj.Top)
            };

            if (item.Fill != null)
            {
                Brush b = null;

                Image texture = null;
                foreach (ImageStylePicker.NamedImage img in FillImages)
                {
                    if (img.Name == item.Fill.FillPattern)
                    {
                        //TODO: Figure out why we can't modify the palette...
                        //TODO: When using the transparent png's, it might be possible to paint it usign only the alpha channel mask
                        /*Image bmp = (Image)img.Image.Clone();
                        for(int i = 0; i < bmp.Palette.Entries.Length; i++)
                            if (bmp.Palette.Entries[i].R == Color.Black.R && bmp.Palette.Entries[i].B == Color.Black.B && bmp.Palette.Entries[i].G == Color.Black.G)
                                bmp.Palette.Entries[i] = item.Fill.ForegroundColor;
                            else if (bmp.Palette.Entries[i].R == Color.White.R && bmp.Palette.Entries[i].B == Color.White.B && bmp.Palette.Entries[i].G == Color.White.G)
                                bmp.Palette.Entries[i] = item.Fill.BackgroundColor;
                        */

                        //Until the above is resolved, this is a VERY slow way to do it, even with app. 200 pixels
                        //Unfortunately I don't want "unsafe" code here...
                        Color? bg = null;
                        Color? fg = null;
                        try
                        {
                            bg = Utility.ParseHTMLColor(item.Fill.BackgroundColor);
                            fg = Utility.ParseHTMLColor(item.Fill.ForegroundColor);
                        }
                        catch { }

                        Bitmap bmp = new Bitmap(img.Image);
                        for (int y = 0; y < bmp.Height; y++)
                            for (int x = 0; x < bmp.Width; x++)
                            {
                                Color c = bmp.GetPixel(x, y);

                                if (c.A > 0x7F && fg.HasValue /*&& c.R == Color.Black.R && c.B == Color.Black.B && c.G == Color.Black.G*/)
                                    bmp.SetPixel(x, y, fg.Value);
                                else if (bg.HasValue)//if (c.R == Color.White.R && c.B == Color.White.B && c.G == Color.White.G)
                                    bmp.SetPixel(x, y, bg.Value);
                            }

                        texture = bmp;
                        break;
                    }
                }

                Color? bgColor = null;
                try
                {
                    bgColor = Utility.ParseHTMLColor(item.Fill.BackgroundColor);
                }
                catch { }
                if (texture == null && bgColor.HasValue)
                    b = new SolidBrush(bgColor.Value);
                else if (texture != null)
                    b = new TextureBrush(texture);

                if (b != null)
                {
                    g.FillPolygon(b, points);
                    b.Dispose();
                }
            }

            if (item.Stroke != null && !string.IsNullOrEmpty(item.Stroke.Color))
            {
                Color? c = null;
                try
                {
                    c = Utility.ParseHTMLColor(item.Stroke.Color);
                }
                catch { }
                if (c.HasValue)
                {
                    using (Pen p = new Pen(c.Value, /*float.Parse(item.Stroke.Thickness)*/ 1)) //TODO: Calculate appropriate thickness
                        g.DrawPolygon(p, points); //TODO: Implement line dash
                }
            }
        }
        public static void RenderPreviewArea(Graphics g, Rectangle size, IAreaSymbolizationFill item)
        {
            if (item == null)
            {
                RenderPreviewFont(g, size, null);
                return;
            }

            //Adjust, since painting always excludes top/right and includes left/bottom
            Rectangle size_adj = new Rectangle(size.X, size.Y, size.Width - 1, size.Height - 1);

            Point[] points =
            {
                new Point(size_adj.Left,  size_adj.Top),
                new Point(size_adj.Right, size_adj.Top),
                new Point(size_adj.Right, size_adj.Bottom),
                new Point(size_adj.Left,  size_adj.Bottom),
                new Point(size_adj.Left,  size_adj.Top)
            };

            if (item.Fill != null)
            {
                Brush b = null;

                Image texture = null;
                foreach (ImageStylePicker.NamedImage img in FillImages)
                {
                    if (img.Name == item.Fill.FillPattern)
                    {
                        //TODO: Figure out why we can't modify the palette...
                        //TODO: When using the transparent png's, it might be possible to paint it usign only the alpha channel mask

                        /*Image bmp = (Image)img.Image.Clone();
                         * for(int i = 0; i < bmp.Palette.Entries.Length; i++)
                         *  if (bmp.Palette.Entries[i].R == Color.Black.R && bmp.Palette.Entries[i].B == Color.Black.B && bmp.Palette.Entries[i].G == Color.Black.G)
                         *      bmp.Palette.Entries[i] = item.Fill.ForegroundColor;
                         *  else if (bmp.Palette.Entries[i].R == Color.White.R && bmp.Palette.Entries[i].B == Color.White.B && bmp.Palette.Entries[i].G == Color.White.G)
                         *      bmp.Palette.Entries[i] = item.Fill.BackgroundColor;
                         */

                        //Until the above is resolved, this is a VERY slow way to do it, even with app. 200 pixels
                        //Unfortunately I don't want "unsafe" code here...
                        Color?bg = null;
                        Color?fg = null;
                        try
                        {
                            bg = Utility.ParseHTMLColor(item.Fill.BackgroundColor);
                            fg = Utility.ParseHTMLColor(item.Fill.ForegroundColor);
                        }
                        catch { }

                        Bitmap bmp = new Bitmap(img.Image);
                        for (int y = 0; y < bmp.Height; y++)
                        {
                            for (int x = 0; x < bmp.Width; x++)
                            {
                                Color c = bmp.GetPixel(x, y);

                                if (c.A > 0x7F && fg.HasValue /*&& c.R == Color.Black.R && c.B == Color.Black.B && c.G == Color.Black.G*/)
                                {
                                    bmp.SetPixel(x, y, fg.Value);
                                }
                                else if (bg.HasValue)//if (c.R == Color.White.R && c.B == Color.White.B && c.G == Color.White.G)
                                {
                                    bmp.SetPixel(x, y, bg.Value);
                                }
                            }
                        }

                        texture = bmp;
                        break;
                    }
                }

                Color?bgColor = null;
                try
                {
                    bgColor = Utility.ParseHTMLColor(item.Fill.BackgroundColor);
                }
                catch { }
                if (texture == null && bgColor.HasValue)
                {
                    b = new SolidBrush(bgColor.Value);
                }
                else if (texture != null)
                {
                    b = new TextureBrush(texture);
                }

                if (b != null)
                {
                    g.FillPolygon(b, points);
                    b.Dispose();
                }
            }

            if (item.Stroke != null && !string.IsNullOrEmpty(item.Stroke.Color))
            {
                Color?c = null;
                try
                {
                    c = Utility.ParseHTMLColor(item.Stroke.Color);
                }
                catch { }
                if (c.HasValue)
                {
                    using (Pen p = new Pen(c.Value, /*float.Parse(item.Stroke.Thickness)*/ 1)) //TODO: Calculate appropriate thickness
                        g.DrawPolygon(p, points);                                              //TODO: Implement line dash
                }
            }
        }