public void Setup()
 {
     _testDeck = new TestDeck(new JavaScriptTranslatorFactory());
     _testLine = new DeckLine(new List<string>());
     _testElement = new ProjectLayoutElement("testElement");
 }
Exemple #2
0
 public ElementString TranslateString(string sRawString, DeckLine zDeckLine, ProjectLayoutElement zElement, bool bPrint, string sCacheSuffix = "")
 {
     return(m_zTranslator.TranslateString(this, sRawString, bPrint ? m_nCardPrintIndex : m_nCardIndex, zDeckLine, zElement, sCacheSuffix));
 }
Exemple #3
0
        public void DrawCard(int nX, int nY, Graphics zGraphics, DeckLine zDeckLine, bool bExport, bool bDrawBackground)
        {
            List<string> listLine = zDeckLine.LineColumns;
            #warning this thing is the main choke point of the app, minimize and cache!
            // Custom Graphics Setting
            zGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            zGraphics.SmoothingMode = SmoothingMode.AntiAlias;
            //zGraphics.SmoothingMode = SmoothingMode.HighQuality;

            var matrixOriginal = zGraphics.Transform;

            // Zoom does not apply to export
            if (!bExport)
            {
                zGraphics.ScaleTransform(ZoomLevel, ZoomLevel);
                // Custom Graphics Setting

                zGraphics.InterpolationMode = 1.0f != ZoomLevel
                    ? InterpolationMode.NearestNeighbor
                    : InterpolationMode.Bilinear;
            }

            //Logger.Clear();
            ProjectLayoutElement zSelectedElement = null;

            if (!bExport)
            {
                zSelectedElement = MDILayoutControl.Instance.GetSelectedLayoutElement();
            }

            // draw the background
            if (bDrawBackground)
            {
                zGraphics.FillRectangle(Brushes.White, nX, nY, CurrentDeck.CardLayout.width,
                    CurrentDeck.CardLayout.height);
            }

            // All drawing is handled in reverse element order

            if (null != CurrentDeck.CardLayout.Element)
            {
                for (var nIdx = CurrentDeck.CardLayout.Element.Length - 1; nIdx > -1; nIdx--)
                {
                    var zElement = CurrentDeck.CardLayout.Element[nIdx];
                    if (zElement.enabled) // only add enabled items to draw
                    {
                        MDIIssues.Instance.SetElementName(zElement.name);

                        // get override Element
                        ProjectLayoutElement zOverrideElement = CurrentDeck.GetOverrideElement(zElement, listLine);
                        var zDrawElement = zOverrideElement;

                        // translate any index values in the csv
                        var zElementString = CurrentDeck.TranslateString(zDrawElement.variable, zDeckLine, zDrawElement, bExport);

                        // enabled is re-checked due to possible override of the enabled value
                        if (!zElementString.DrawElement || !zDrawElement.enabled)
                        {
                            continue;
                        }

                        var eType = DrawItem.GetElementType(zDrawElement.type);

                        //NOTE: removed transform backup (draw element resets it anyway...)
                        //if (!bExport) // backup is only necessary for zoomed canvas
                        //{
                            //matrixPrevious = zGraphics.Transform;
                        //}
                        DrawItem.DrawElement(zGraphics, CurrentDeck, zDrawElement, eType, nX, nY, zElementString.String);
                        if (!bExport)
                        {
                            //zGraphics.Transform = matrixPrevious;
                            zGraphics.ScaleTransform(ZoomLevel, ZoomLevel);
                        }
                    }
                }

                if (!bExport)
                {
                    // draw all selections and element borders after everything else
                    for (var nIdx = CurrentDeck.CardLayout.Element.Length - 1; nIdx > -1; nIdx--)
                    {
                        ProjectLayoutElement zElement = CurrentDeck.CardLayout.Element[nIdx];
                        if (zElement.enabled) // only add enabled items to draw
                        {
                            var bDrawSelection = zSelectedElement == zElement;

                            if (DrawElementBorder)
                            {
                                var matrixPrevious = zGraphics.Transform;
                                DrawItem.DrawElementDebugBorder(zGraphics, zElement, nX, nY, bDrawSelection);
                                zGraphics.Transform = matrixPrevious;
                            }
                        }
                    }
                }
            }

            // draw the card border
            if ((bExport && CardMakerMDI.Instance.PrintLayoutBorder) || (!bExport && CurrentDeck.CardLayout.drawBorder))
            {
                // note that the border is inclusive in the width/height consuming 2 pixels (0 to total-1)
                zGraphics.DrawRectangle(Pens.Black, nX, nY, CurrentDeck.CardLayout.width - 1, CurrentDeck.CardLayout.height - 1);
            }

            zGraphics.Transform = matrixOriginal;
        }
Exemple #4
0
        public void DrawCard(int nX, int nY, Graphics zGraphics, DeckLine zDeckLine, bool bExport, bool bDrawBackground)
        {
            List <string> listLine = zDeckLine.LineColumns;

            // Custom Graphics Setting
            zGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            zGraphics.SmoothingMode     = SmoothingMode.AntiAlias;
            //zGraphics.SmoothingMode = SmoothingMode.HighQuality;

            var matrixOriginal = zGraphics.Transform;

            // Zoom does not apply to export
            if (!bExport)
            {
                zGraphics.ScaleTransform(ZoomLevel, ZoomLevel);
                // Custom Graphics Setting

                zGraphics.InterpolationMode = 1.0f != ZoomLevel
                    ? InterpolationMode.NearestNeighbor
                    : InterpolationMode.Bilinear;
            }

            //Logger.Clear();
            ProjectLayoutElement zSelectedElement = null;

            if (!bExport)
            {
                zSelectedElement = ElementManager.Instance.GetSelectedElement();
            }

            // draw the background
            if (bDrawBackground)
            {
                zGraphics.FillRectangle(Brushes.White, nX, nY, CurrentDeck.CardLayout.width,
                                        CurrentDeck.CardLayout.height);
            }

            // All drawing is handled in reverse element order

            if (null != CurrentDeck.CardLayout.Element)
            {
                for (var nIdx = CurrentDeck.CardLayout.Element.Length - 1; nIdx > -1; nIdx--)
                {
                    var zElement = CurrentDeck.CardLayout.Element[nIdx];
                    if (zElement.enabled) // only add enabled items to draw
                    {
                        IssueManager.Instance.FireChangeElementEvent(zElement.name);

                        // get override Element
                        ProjectLayoutElement zOverrideElement = CurrentDeck.GetOverrideElement(zElement, listLine, zDeckLine, bExport);
                        var zDrawElement = zOverrideElement;

                        // translate any index values in the csv
                        var zElementString = CurrentDeck.TranslateString(zDrawElement.variable, zDeckLine, zDrawElement, bExport);

                        // enabled is re-checked due to possible override of the enabled value
                        if (!zElementString.DrawElement || !zDrawElement.enabled)
                        {
                            continue;
                        }

                        var eType = DrawItem.GetElementType(zDrawElement.type);

                        //NOTE: removed transform backup (draw element resets it anyway...)
                        //if (!bExport) // backup is only necessary for zoomed canvas
                        //{
                        //matrixPrevious = zGraphics.Transform;
                        //}
                        DrawItem.DrawElement(zGraphics, CurrentDeck, zDrawElement, eType, nX, nY, zElementString.String, bExport);
                        if (!bExport)
                        {
                            //zGraphics.Transform = matrixPrevious;
                            zGraphics.ScaleTransform(ZoomLevel, ZoomLevel);
                        }
                    }
                }

                if (!bExport)
                {
                    // draw all selections and element borders after everything else
                    for (var nIdx = CurrentDeck.CardLayout.Element.Length - 1; nIdx > -1; nIdx--)
                    {
                        ProjectLayoutElement zElement = CurrentDeck.CardLayout.Element[nIdx];
                        if (zElement.enabled) // only add enabled items to draw
                        {
                            var bDrawSelection = zSelectedElement == zElement;

                            if (CardMakerInstance.DrawElementBorder)
                            {
                                var matrixPrevious = zGraphics.Transform;
                                DrawItem.DrawElementDebugBorder(zGraphics, zElement, nX, nY, bDrawSelection);
                                zGraphics.Transform = matrixPrevious;
                            }
                        }
                    }
                }
            }
            // draw the card border
            if ((bExport && CardMakerSettings.PrintLayoutBorder) || (!bExport && CurrentDeck.CardLayout.drawBorder))
            {
                // note that the border is inclusive in the width/height consuming 2 pixels (0 to total-1)
                zGraphics.DrawRectangle(Pens.Black, nX, nY, CurrentDeck.CardLayout.width - 1, CurrentDeck.CardLayout.height - 1);
            }

            zGraphics.Transform = matrixOriginal;
        }
Exemple #5
0
 public ProjectLayoutElement GetOverrideElement(ProjectLayoutElement zElement, DeckLine zDeckLine, bool bExport)
 {
     return(m_zTranslator.GetOverrideElement(this, zElement, bExport ? m_nCardPrintIndex : m_nCardIndex, zDeckLine.LineColumns, zDeckLine));
 }
 public void Setup()
 {
     _testDeck = new TestDeck();
     _testLine = new DeckLine(new List<string>());
     _testElement = new ProjectLayoutElement("testElement");
 }
Exemple #7
0
        public void DrawCard(int nX, int nY, Graphics zGraphics, DeckLine zDeckLine, bool bExport, bool bDrawBackground)
        {
            // Custom Graphics Setting
            zGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
            zGraphics.SmoothingMode     = SmoothingMode.AntiAlias;
            //zGraphics.SmoothingMode = SmoothingMode.HighQuality;

            var matrixOriginal = zGraphics.Transform;

            // Zoom does not apply to export
            if (!bExport)
            {
                zGraphics.ScaleTransform(ZoomLevel, ZoomLevel);
                // Custom Graphics Setting

                zGraphics.InterpolationMode = 1.0f != ZoomLevel
                    ? InterpolationMode.NearestNeighbor
                    : InterpolationMode.Bilinear;
            }

            // draw the card background
            if (bDrawBackground)
            {
                zGraphics.FillRectangle(Brushes.White, nX, nY, CurrentDeck.CardLayout.width,
                                        CurrentDeck.CardLayout.height);
            }

            // All drawing is handled in reverse element order

            if (null != CurrentDeck.CardLayout.Element)
            {
                for (var nIdx = CurrentDeck.CardLayout.Element.Length - 1; nIdx > -1; nIdx--)
                {
                    var zElement = CurrentDeck.CardLayout.Element[nIdx];
                    if (zElement.enabled) // only add enabled items to draw
                    {
                        IssueManager.Instance.FireChangeElementEvent(zElement.name);

                        // get override Element (overrides based on data source) (this is a copy!)
                        // This takes place before translation to cover the odd case where the variable field is override in the data source
                        var zDrawElement = CurrentDeck.GetOverrideElement(zElement, zDeckLine, bExport);

                        // translate any index values in the csv
                        var zElementString = CurrentDeck.TranslateString(zDrawElement.variable, zDeckLine, zDrawElement, bExport);

                        // get override Element (based on any overrides in the element variable string)
                        zDrawElement = CurrentDeck.GetVariableOverrideElement(zDrawElement, zElementString.OverrideFieldToValueDictionary);

                        // enabled is re-checked due to possible override of the enabled value
                        if (!zElementString.DrawElement || !zDrawElement.enabled)
                        {
                            continue;
                        }

                        // initialize the translated fields on the element to draw
                        zDrawElement.InitializeTranslatedFields();

                        DrawElement(zGraphics, CurrentDeck, zDrawElement, nX, nY, zElementString.String, bExport);
                        if (!bExport)
                        {
                            zGraphics.ScaleTransform(ZoomLevel, ZoomLevel);
                        }
                    }
                }

                if (!bExport)
                {
                    // draw all selections and element borders after everything else
                    for (var nIdx = CurrentDeck.CardLayout.Element.Length - 1; nIdx > -1; nIdx--)
                    {
                        var zElement = ProjectManager.Instance.LookupElementReference(CurrentDeck.CardLayout.Element[nIdx]);
                        if (zElement.enabled) // only add enabled items to draw
                        {
                            DrawElementDebugBorder(zGraphics, zElement, nX, nY, ElementManager.Instance.GetSelectedElement() == zElement);
                        }
                    }
                }
            }

            DrawLayoutDividers(zGraphics, bExport);
            DrawBorder(zGraphics, nX, nY, CurrentDeck.CardLayout.width, CurrentDeck.CardLayout.height, CurrentDeck.CardLayout, bExport);

            zGraphics.Transform = matrixOriginal;
        }
Exemple #8
0
        /// <summary>
        /// Translates the string representing the element. (also handles any nodraw text input)
        /// </summary>
        /// <param name="sRawString"></param>
        /// <param name="listLine"></param>
        /// <param name="zElement"></param>
        /// <param name="bPrint"></param>
        /// <returns></returns>
        public ElementString TranslateString(string sRawString, DeckLine zDeckLine, ProjectLayoutElement zElement, bool bPrint)
        {
            List<string> listLine = zDeckLine.LineColumns;

            ElementString zCached;
            if (m_dictionaryElementStringCache.TryGetValue(zElement.name, out zCached))
            {
                return zCached;
            } 
            
            string sOutput = sRawString;

            sOutput = sOutput.Replace("#empty", string.Empty);

            var zElementString = new ElementString();

            // Translate named items (column names / defines)
            //Groups
            //    1    2    3   4   5
            //@"(.*)(@\[)(.+?)(\])(.*)"
            Match zMatch;
            while (s_regexColumnVariable.IsMatch(sOutput))
            {
                zMatch = s_regexColumnVariable.Match(sOutput);
                int nIndex;
                string sDefineValue;
                var sKey = zMatch.Groups[3].ToString().ToLower();

                // check the key for untranslated components
                var arrayParams = sKey.Split(new char[] {','});
                if (arrayParams.Length > 1)
                {
                    sKey = arrayParams[0];
                }

                if (m_dictionaryDefines.TryGetValue(sKey, out sDefineValue))
                {
                }
                else if (m_dictionaryColumnNames.TryGetValue(sKey, out nIndex))
                {
                    sDefineValue = (nIndex >= listLine.Count ? string.Empty : listLine[nIndex].Trim());
                }
                else
                {
                    MDIIssues.Instance.AddIssue("Bad reference key: " + sKey);
                    sDefineValue = "[BAD NAME: " + sKey + "]";
                }
                if (arrayParams.Length > 1)
                {
                    for (int nIdx = 1; nIdx < arrayParams.Length; nIdx++)
                    {
                        sDefineValue = sDefineValue.Replace("{" + nIdx + "}", arrayParams[nIdx]);
                    }
                }
                sOutput = zMatch.Groups[1] + sDefineValue + zMatch.Groups[5];
            }
            
            // Translate card counter/index
            // Groups                 
            //     1   2    3  4    5  6    7  8   9
            //(@"(.*)(##)(\d+)(;)(\d+)(;)(\d+)(#)(.*)");
            while (s_regexCardCounter.IsMatch(sOutput))
            {
                zMatch = s_regexCardCounter.Match(sOutput);
                var nStart = Int32.Parse(zMatch.Groups[3].ToString());
                var nChange = Int32.Parse(zMatch.Groups[5].ToString());
                var nLeftPad = Int32.Parse(zMatch.Groups[7].ToString());

                var nIndex = bPrint ? m_nCardPrintIndex : m_nCardIndex;

                sOutput = zMatch.Groups[1] +
                    // nIndex is left as is (not adding 1)
                    (nStart + (nIndex * nChange)).ToString(CultureInfo.InvariantCulture).PadLeft(nLeftPad, '0') +
                    zMatch.Groups[9];
            }

            // Translate sub card counter/index
            // Groups                 
            //     1   2    3  4    5  6    7  8   9
            //(@"(.*)(#sc;)(\d+)(;)(\d+)(;)(\d+)(#)(.*)");
            while (s_regexSubCardCounter.IsMatch(sOutput))
            {
                zMatch = s_regexSubCardCounter.Match(sOutput);
                var nStart = Int32.Parse(zMatch.Groups[3].ToString());
                var nChange = Int32.Parse(zMatch.Groups[5].ToString());
                var nLeftPad = Int32.Parse(zMatch.Groups[7].ToString());

                var nIndex = zDeckLine.RowSubIndex;

                sOutput = zMatch.Groups[1] +
                    // nIndex is left as is (not adding 1)
                    (nStart + (nIndex * nChange)).ToString(CultureInfo.InvariantCulture).PadLeft(nLeftPad, '0') +
                    zMatch.Groups[9];
            }

            // Translate If Logic
            //Groups
            //    1     2    3    4   5 
            //@"(.*)(#\()(if.+)(\)#)(.*)");
            while (s_regexIfLogic.IsMatch(sOutput))
            {
                zMatch = s_regexIfLogic.Match(sOutput);
                string sLogicResult = TranslateIfLogic(zMatch.Groups[3].ToString());
                if (sLogicResult.Trim().Equals("#nodraw", StringComparison.CurrentCultureIgnoreCase))
                    zElementString.DrawElement = false;
                sOutput = zMatch.Groups[1] +
                    sLogicResult +
                    zMatch.Groups[5];
            }

            // Translate Switch Logic
            //Groups                  
            //    1     2        3    4   5 
            //@"(.*)(#\()(switch.+)(\)#)(.*)");
            while (s_regexSwitchLogic.IsMatch(sOutput))
            {
                zMatch = s_regexSwitchLogic.Match(sOutput);
                string sLogicResult = TranslateSwitchLogic(zMatch.Groups[3].ToString());
                if (sLogicResult.Trim().Equals("#nodraw", StringComparison.CurrentCultureIgnoreCase))
                    zElementString.DrawElement = false;
                
                sOutput = zMatch.Groups[1] +
                    sLogicResult +
                    zMatch.Groups[5];
            }

            switch ((ElementType)Enum.Parse(typeof(ElementType), zElement.type))
            {
                case ElementType.Text:
                    sOutput = sOutput.Replace("\\n", Environment.NewLine);
                    sOutput = sOutput.Replace("\\q", "\"");
                    sOutput = sOutput.Replace("\\c", ",");
                    sOutput = sOutput.Replace("&gt;", ">");
                    sOutput = sOutput.Replace("&lt;", "<");
                    break;
                case ElementType.FormattedText:
                    sOutput = sOutput.Replace("<c>", ",");
                    sOutput = sOutput.Replace("<q>", "\"");
                    sOutput = sOutput.Replace("&gt;", ">");
                    sOutput = sOutput.Replace("&lt;", "<");
                    break;
            }

            zElementString.String = sOutput;

            AddStringToTranslationCache(zElement.name, zElementString);

            return zElementString;
        }
Exemple #9
0
 public ProjectLayoutElement GetOverrideElement(ProjectLayoutElement zElement, List<string> arrayLine, DeckLine zDeckLine, bool bExport)
 {
     return m_zTranslator.GetOverrideElement(zElement, bExport ? m_nCardPrintIndex : m_nCardIndex, arrayLine, zDeckLine);
 }
Exemple #10
0
 public ElementString TranslateString(string sRawString, DeckLine zDeckLine,
     ProjectLayoutElement zElement, bool bPrint, string sCacheSuffix = "")
 {
     return m_zTranslator.TranslateString(sRawString, bPrint ? m_nCardPrintIndex : m_nCardIndex, zDeckLine, zElement, sCacheSuffix);
 }
Exemple #11
0
 public ProjectLayoutElement GetOverrideElement(ProjectLayoutElement zElement, List <string> arrayLine, DeckLine zDeckLine, bool bExport)
 {
     return(m_zTranslator.GetOverrideElement(zElement, bExport ? m_nCardPrintIndex : m_nCardIndex, arrayLine, zDeckLine));
 }
Exemple #12
0
        public ProjectLayoutElement GetOverrideElement(ProjectLayoutElement zElement, List<string> arrayLine, DeckLine zDeckLine, bool bExport)
        {
            Dictionary<string, int> dictionaryOverrideColumns;
            string sNameLower = zElement.name.ToLower();
            m_dictionaryElementOverrides.TryGetValue(sNameLower, out dictionaryOverrideColumns);
            if (null == dictionaryOverrideColumns)
            {
                return zElement;
            }

            var zOverrideElement = new ProjectLayoutElement();
            zOverrideElement.DeepCopy(zElement, false);
            zOverrideElement.name = zElement.name;

            foreach (string sKey in dictionaryOverrideColumns.Keys)
            {
                Type zType = typeof(ProjectLayoutElement);
                PropertyInfo zProperty = zType.GetProperty(sKey);
                if (null != zProperty && zProperty.CanWrite)
                {
                    MethodInfo zMethod = zProperty.GetSetMethod();
                    int nOverrideValueColumnIdx = dictionaryOverrideColumns[sKey];
                    if (arrayLine.Count <= nOverrideValueColumnIdx)
                    {
                        continue;
                    }
                    string sValue = arrayLine[nOverrideValueColumnIdx].Trim();

                    // Note: TranslateString maintains an element name based cache, the key is critical to make this translation unique
                    sValue = TranslateString(sValue, zDeckLine, zOverrideElement, bExport, sKey).String;

                    if (!string.IsNullOrEmpty(sValue))
                    {
                        if (zProperty.PropertyType == typeof(string))
                        {
                            zMethod.Invoke(zOverrideElement, new object[] { sValue });
                        }
                        else if (zProperty.PropertyType == typeof(float))
                        {
                            float fValue;
                            if (float.TryParse(sValue, out fValue))
                            {
                                zMethod.Invoke(zOverrideElement, new object[] { fValue });
                            }
                        }
                        else if (zProperty.PropertyType == typeof(bool))
                        {
                            bool bValue;
                            if (bool.TryParse(sValue, out bValue))
                            {
                                zMethod.Invoke(zOverrideElement, new object[] { bValue });
                            }
                        }
                        else if (zProperty.PropertyType == typeof(Int32))
                        {
                            int nValue;
                            if (int.TryParse(sValue, out nValue))
                            {
                                zMethod.Invoke(zOverrideElement, new object[] { nValue });
                            }
                        }
                    }
                }
            }
            zOverrideElement.InitializeCache(); // any cached items must be recached
            return zOverrideElement;
        }