示例#1
0
        public void ExportThread()
        {
            var zWait = WaitDialog.Instance;

            zWait.ProgressReset(0, 0, ExportLayoutEndIndex - ExportLayoutStartIndex, 0);
            for (var nIdx = ExportLayoutStartIndex; nIdx < ExportLayoutEndIndex; nIdx++)
            {
                ChangeExportLayoutIndex(nIdx);
                var nPadSize = CurrentDeck.CardCount.ToString(CultureInfo.InvariantCulture).Length;
                zWait.ProgressReset(1, 0, CurrentDeck.CardCount, 0);

                var exportWidth = CurrentDeck.CardLayout.exportWidth == 0
                    ? CurrentDeck.CardLayout.width : CurrentDeck.CardLayout.exportWidth;

                var exportHeight = CurrentDeck.CardLayout.exportHeight == 0
                    ? CurrentDeck.CardLayout.height : CurrentDeck.CardLayout.exportHeight;

                if (CurrentDeck.CardLayout.width > exportWidth ||
                    CurrentDeck.CardLayout.height > exportHeight)
                {
                    Logger.AddLogLine(
                        $"ERROR: Layout: [{CurrentDeck.CardLayout.Name}] exportWidth and/or exportHeight too small! (Skipping export)");
                    continue;
                }

                UpdateBufferBitmap(exportWidth, exportHeight);
                var zGraphics = Graphics.FromImage(m_zExportCardBuffer);
                var nCardIdx  = 0;
                do
                {
                    var nX = 0;
                    var nY = 0;
                    var nCardsExportedInImage = 0;
                    zGraphics.Clear(CurrentDeck.CardLayout.exportTransparentBackground ?
                                    Color.FromArgb(0, 0, 0, 0) :
                                    Color.White);
                    do
                    {
                        CurrentDeck.ResetDeckCache();
                        CurrentDeck.CardPrintIndex = nCardIdx++;
                        nCardsExportedInImage++;
                        CardRenderer.DrawPrintLineToGraphics(zGraphics, nX, nY, !CurrentDeck.CardLayout.exportTransparentBackground);
                        m_zExportCardBuffer.SetResolution(CurrentDeck.CardLayout.dpi, CurrentDeck.CardLayout.dpi);

                        zWait.ProgressStep(1);

                        int nMoveCount = 1;
                        if (m_nSkipStitchIndex > 0)
                        {
                            var x = ((nCardsExportedInImage + 1) % m_nSkipStitchIndex);
                            if (x == 0)
                            {
                                // shift forward an extra spot to ignore the dummy index
                                nMoveCount = 2;
                            }
                        }

                        var bOutOfSpace = false;
                        for (int nShift = 0; nShift < nMoveCount; nShift++)
                        {
                            nX += CurrentDeck.CardLayout.width + CurrentDeck.CardLayout.buffer;
                            if (nX + CurrentDeck.CardLayout.width > exportWidth)
                            {
                                nX  = 0;
                                nY += CurrentDeck.CardLayout.height + CurrentDeck.CardLayout.buffer;
                            }
                            if (nY + CurrentDeck.CardLayout.height > exportHeight)
                            {
                                // no more space
                                bOutOfSpace = true;
                                break;
                            }
                        }

                        if (bOutOfSpace)
                        {
                            break;
                        }
                    } while (nCardIdx < CurrentDeck.CardCount);

                    string sFileName;

                    // NOTE: nCardIdx at this point is 1 more than the actual index ... how convenient for export file names...

                    if (!string.IsNullOrEmpty(m_sOverrideStringFormat))
                    {
                        // check for the super override
                        sFileName = CurrentDeck.TranslateFileNameString(m_sOverrideStringFormat, nCardIdx, nPadSize);
                    }
                    else if (!string.IsNullOrEmpty(CurrentDeck.CardLayout.exportNameFormat))
                    {
                        // check for the per layout override
                        sFileName = CurrentDeck.TranslateFileNameString(CurrentDeck.CardLayout.exportNameFormat, nCardIdx, nPadSize);
                    }
                    else // default
                    {
                        sFileName = CurrentDeck.CardLayout.Name + "_" + (nCardIdx).ToString(CultureInfo.InvariantCulture).PadLeft(nPadSize, '0');
                    }
                    try
                    {
                        ProcessRotateExport(m_zExportCardBuffer, CurrentDeck.CardLayout, false);
                        m_zExportCardBuffer.Save(
                            m_sExportFolder + sFileName +
                            "." + m_eImageFormat.ToString().ToLower(),
                            m_eImageFormat);
                        ProcessRotateExport(m_zExportCardBuffer, CurrentDeck.CardLayout, true);
                    }
                    catch (Exception)
                    {
                        Logger.AddLogLine("Invalid Filename or IO error: " + sFileName);
                        zWait.ThreadSuccess = false;
                        zWait.CloseWaitDialog();
                        return;
                    }
                } while (nCardIdx < CurrentDeck.CardCount);
                zWait.ProgressStep(0);
            }

            zWait.ThreadSuccess = true;
            zWait.CloseWaitDialog();
        }
示例#2
0
        public override void ExportThread()
        {
            var progressLayoutIdx = ProgressReporter.GetProgressIndex(ProgressName.LAYOUT);
            var progressCardIdx   = ProgressReporter.GetProgressIndex(ProgressName.CARD);

            ProgressReporter.ProgressReset(progressLayoutIdx, 0, ExportLayoutIndices.Length, 0);
            foreach (var nIdx in ExportLayoutIndices)
            {
                ChangeExportLayoutIndex(nIdx);
                if (CurrentDeck.EmptyReference)
                {
                    // empty reference layouts are not exported
                    ProgressReporter.ProgressStep(progressLayoutIdx);
                    continue;
                }
                var nPadSize = CurrentDeck.CardCount.ToString(CultureInfo.InvariantCulture).Length;
                ProgressReporter.ProgressReset(progressCardIdx, 0, CurrentDeck.CardCount, 0);

                var exportWidth = CurrentDeck.CardLayout.exportWidth == 0
                    ? CurrentDeck.CardLayout.width : CurrentDeck.CardLayout.exportWidth;

                var exportHeight = CurrentDeck.CardLayout.exportHeight == 0
                    ? CurrentDeck.CardLayout.height : CurrentDeck.CardLayout.exportHeight;

                if (CurrentDeck.CardLayout.width > exportWidth ||
                    CurrentDeck.CardLayout.height > exportHeight)
                {
                    Logger.AddLogLine(
                        $"ERROR: Layout: [{CurrentDeck.CardLayout.Name}] exportWidth and/or exportHeight too small! (Skipping export)");
                    continue;
                }

                UpdateBufferBitmap(exportWidth, exportHeight);
                var zGraphics        = Graphics.FromImage(m_zExportCardBuffer);
                var arrayCardIndices = GetCardIndicesArray(CurrentDeck);
                for (var nCardArrayIdx = 0; nCardArrayIdx < arrayCardIndices.Length; nCardArrayIdx++)
                {
                    var nCardId = arrayCardIndices[nCardArrayIdx];
                    var nX      = 0;
                    var nY      = 0;
                    var nCardsExportedInImage = 0;
                    zGraphics.Clear(CurrentDeck.CardLayout.exportTransparentBackground ?
                                    CardMakerConstants.NoColor :
                                    Color.White);
                    do
                    {
                        CurrentDeck.ResetDeckCache();
                        // HACK - the printcard index is 0 based but all other uses of nCardId are 1 based (so ++ it!)
                        CurrentDeck.CardPrintIndex = nCardId++;
                        nCardsExportedInImage++;
                        CardRenderer.DrawPrintLineToGraphics(zGraphics, nX, nY, !CurrentDeck.CardLayout.exportTransparentBackground);
                        m_zExportCardBuffer.SetResolution(CurrentDeck.CardLayout.dpi, CurrentDeck.CardLayout.dpi);

                        ProgressReporter.ProgressStep(progressCardIdx);

                        int nMoveCount = 1;
                        if (m_nSkipStitchIndex > 0)
                        {
                            var x = ((nCardsExportedInImage + 1) % m_nSkipStitchIndex);
                            if (x == 0)
                            {
                                // shift forward an extra spot to ignore the dummy index
                                nMoveCount = 2;
                            }
                        }

                        var bOutOfSpace = false;
                        for (int nShift = 0; nShift < nMoveCount; nShift++)
                        {
                            nX += CurrentDeck.CardLayout.width + CurrentDeck.CardLayout.buffer;
                            if (nX + CurrentDeck.CardLayout.width > exportWidth)
                            {
                                nX  = 0;
                                nY += CurrentDeck.CardLayout.height + CurrentDeck.CardLayout.buffer;
                            }
                            if (nY + CurrentDeck.CardLayout.height > exportHeight)
                            {
                                // no more space
                                bOutOfSpace = true;
                                break;
                            }
                        }

                        if (bOutOfSpace)
                        {
                            break;
                        }
                    } while (nCardArrayIdx < CurrentDeck.CardCount);

                    string sFileName;

                    // NOTE: nCardId at this point is 1 more than the actual index ... how convenient for export file names...

                    if (!string.IsNullOrEmpty(m_sOverrideStringFormat))
                    {
                        // check for the super override
                        sFileName = CurrentDeck.TranslateFileNameString(m_sOverrideStringFormat, nCardId, nPadSize);
                    }
                    else if (!string.IsNullOrEmpty(CurrentDeck.CardLayout.exportNameFormat))
                    {
                        // check for the per layout override
                        sFileName = CurrentDeck.TranslateFileNameString(CurrentDeck.CardLayout.exportNameFormat, nCardId, nPadSize);
                    }
                    else // default
                    {
                        sFileName = CurrentDeck.CardLayout.Name + "_" + (nCardId).ToString(CultureInfo.InvariantCulture).PadLeft(nPadSize, '0');
                    }
                    try
                    {
                        ProcessRotateExport(m_zExportCardBuffer, CurrentDeck.CardLayout, false);
                        m_zExportCardBuffer.Save(
                            m_sExportFolder + sFileName +
                            "." + m_eImageFormat.ToString().ToLower(),
                            m_eImageFormat);
                        ProcessRotateExport(m_zExportCardBuffer, CurrentDeck.CardLayout, true);
                    }
                    catch (Exception ex)
                    {
                        ProgressReporter.AddIssue("Invalid Filename or IO error: " + sFileName + " :: " + ex.Message);
                        ProgressReporter.ThreadSuccess = false;
                        ProgressReporter.Shutdown();
                        return;
                    }
                }
                ProgressReporter.ProgressStep(progressLayoutIdx);
            }

            ProgressReporter.ThreadSuccess = true;
            ProgressReporter.Shutdown();
        }
示例#3
0
        public void ExportThread()
        {
            var zWait = WaitDialog.Instance;

            zWait.ProgressReset(0, 0, ExportLayoutEndIndex - ExportLayoutStartIndex, 0);
            ChangeExportLayoutIndex(ExportLayoutStartIndex);
            var nPadSize = CurrentDeck.CardCount.ToString(CultureInfo.InvariantCulture).Length;

            zWait.ProgressReset(1, 0, CurrentDeck.CardCount, 0);

            UpdateBufferBitmap(CurrentDeck.CardLayout.width, CurrentDeck.CardLayout.height);

            var zGraphics = Graphics.FromImage(m_zExportCardBuffer);
            var nCardIdx  = m_nImageExportIndex;

            zGraphics.Clear(CurrentDeck.CardLayout.exportTransparentBackground ?
                            CardMakerConstants.NoColor :
                            Color.White);
            CurrentDeck.ResetDeckCache();
            CurrentDeck.CardPrintIndex = nCardIdx++;
            CardRenderer.DrawPrintLineToGraphics(zGraphics, 0, 0, !CurrentDeck.CardLayout.exportTransparentBackground);
            m_zExportCardBuffer.SetResolution(CurrentDeck.CardLayout.dpi, CurrentDeck.CardLayout.dpi);

            zWait.ProgressStep(1);

            string sFileName;

            // NOTE: nCardIdx at this point is 1 more than the actual index ... how convenient for export file names...

            if (!string.IsNullOrEmpty(m_sOverrideStringFormat))
            {
                // check for the super override
                sFileName = CurrentDeck.TranslateFileNameString(m_sOverrideStringFormat, nCardIdx, nPadSize);
            }
            else if (!string.IsNullOrEmpty(CurrentDeck.CardLayout.exportNameFormat))
            {
                // check for the per layout override
                sFileName = CurrentDeck.TranslateFileNameString(CurrentDeck.CardLayout.exportNameFormat, nCardIdx, nPadSize);
            }
            else // default
            {
                sFileName = CurrentDeck.CardLayout.Name + "_" + (nCardIdx).ToString(CultureInfo.InvariantCulture).PadLeft(nPadSize, '0');
            }
            try
            {
                ProcessRotateExport(m_zExportCardBuffer, CurrentDeck.CardLayout, false);
                m_zExportCardBuffer.Save(
                    m_sExportFolder + sFileName +
                    "." + m_eImageFormat.ToString().ToLower(),
                    m_eImageFormat);
                ProcessRotateExport(m_zExportCardBuffer, CurrentDeck.CardLayout, true);
            }
            catch (Exception)
            {
                Logger.AddLogLine("Invalid Filename or IO error: " + sFileName);
                zWait.ThreadSuccess = false;
                zWait.CloseWaitDialog();
                return;
            }

            zWait.ProgressStep(0);

            zWait.ThreadSuccess = true;
            zWait.CloseWaitDialog();
        }
示例#4
0
        public override void ExportThread()
        {
            var progressLayoutIdx = ProgressReporter.GetProgressIndex(ProgressName.LAYOUT);
            var progressCardIdx   = ProgressReporter.GetProgressIndex(ProgressName.CARD);

            ProgressReporter.ProgressReset(progressLayoutIdx, 0, ExportLayoutIndices.Length, 0);
            ChangeExportLayoutIndex(ExportLayoutIndices[0]);
            var nPadSize = CurrentDeck.CardCount.ToString(CultureInfo.InvariantCulture).Length;

            ProgressReporter.ProgressReset(progressCardIdx, 0, CurrentDeck.CardCount, 0);

            UpdateBufferBitmap(CurrentDeck.CardLayout.width, CurrentDeck.CardLayout.height);

            var zGraphics = Graphics.FromImage(m_zExportCardBuffer);
            var nCardIdx  = m_nImageExportIndex;

            zGraphics.Clear(CurrentDeck.CardLayout.exportTransparentBackground ?
                            CardMakerConstants.NoColor :
                            Color.White);
            CurrentDeck.ResetDeckCache();
            CurrentDeck.CardPrintIndex = nCardIdx++;
            CardRenderer.DrawPrintLineToGraphics(zGraphics, 0, 0, !CurrentDeck.CardLayout.exportTransparentBackground);
            m_zExportCardBuffer.SetResolution(CurrentDeck.CardLayout.dpi, CurrentDeck.CardLayout.dpi);

            ProgressReporter.ProgressStep(progressCardIdx);

            string sFileName;

            // NOTE: nCardIdx at this point is 1 more than the actual index ... how convenient for export file names...

            if (!string.IsNullOrEmpty(m_sOverrideStringFormat))
            {
                // check for the super override
                sFileName = CurrentDeck.TranslateFileNameString(m_sOverrideStringFormat, nCardIdx, nPadSize);
            }
            else if (!string.IsNullOrEmpty(CurrentDeck.CardLayout.exportNameFormat))
            {
                // check for the per layout override
                sFileName = CurrentDeck.TranslateFileNameString(CurrentDeck.CardLayout.exportNameFormat, nCardIdx, nPadSize);
            }
            else // default
            {
                sFileName = CurrentDeck.CardLayout.Name + "_" + (nCardIdx).ToString(CultureInfo.InvariantCulture).PadLeft(nPadSize, '0');
            }
            try
            {
                ProcessRotateExport(m_zExportCardBuffer, CurrentDeck.CardLayout, false);
                m_zExportCardBuffer.Save(
                    m_sExportFolder + sFileName +
                    "." + m_eImageFormat.ToString().ToLower(),
                    m_eImageFormat);
                ProcessRotateExport(m_zExportCardBuffer, CurrentDeck.CardLayout, true);
            }
            catch (Exception e)
            {
                ProgressReporter.AddIssue("Invalid Filename or IO error: {0} {1}".FormatString(sFileName, e.Message));
                ProgressReporter.ThreadSuccess = false;
                ProgressReporter.Shutdown();
                return;
            }

            ProgressReporter.ProgressStep(progressLayoutIdx);

            ProgressReporter.ThreadSuccess = true;
            ProgressReporter.Shutdown();
        }