Ejemplo n.º 1
0
 private void btnPageSelect_Click(object sender, EventArgs e)
 {
     GUIElements.PageOverview po = new GUIElements.PageOverview(doc, this, inkControl1.Page);
     po.ItemSelected += new EventHandler <int>(delegate(object selSender, int selInd)
     {
         if (selInd < doc.Pages.Count)
         {
             inkControl1.LoadPage(doc.Pages[selInd]);
         }
         else if (selInd == doc.Pages.Count)
         {
             KPage page  = new KPage(doc);
             var formats = PageFormat.GetFormats();
             if (formats.ContainsKey(doc.DefaultFormat))
             {
                 page.Format = formats[doc.DefaultFormat];
             }
             else
             {
                 page.Format = PageFormat.A4;
             }
             page.Background = new Backgrounds.BackgroundQuadPaper5mm();
             doc.Pages.Add(page);
             inkControl1.LoadPage(page);
         }
     });
     OpenDialog(po);
 }
Ejemplo n.º 2
0
        public static void StoreState(KPage page)
        {
            if (!history.ContainsKey(page))
            {
                history.Add(page, new History());
            }

            var vers  = history[page].Versions;
            int start = history[page].Current + 1;

            if (start < vers.Count)
            {
                vers.RemoveRange(start, vers.Count - start);
            }

            HistoryEntry entry = new HistoryEntry()
            {
                Page = page,
                Data = E.GetBytes(page.SaveToString())
            };

            history[page].Versions.Add(entry);
            history[page].Current++;
            SetButtonVisibility(page);
        }
Ejemplo n.º 3
0
 public void LoadPage(KPage page)
 {
     this.page?.OnHide();
     this.page?.BackgroundImage?.UnloadGPU();
     this.page?.RemoveSelectionChangedEventHandler();
     this.page = page;
     this.page.OnShow(this);
     //ResetTransformation(true);
     RefreshPage();
     this.page.SelectionChanged += Page_SelectionChanged;
     PageLoaded?.Invoke(this, page);
 }
Ejemplo n.º 4
0
 public static void SetButtonVisibility(KPage page)
 {
     if (!history.ContainsKey(page))
     {
         return;
     }
     if (btnUndo != null)
     {
         btnUndo.Enabled = history[page].Current > 0;
     }
     if (btnRedo != null)
     {
         btnRedo.Enabled = history[page].Current < history[page].Versions.Count - 1;
     }
 }
Ejemplo n.º 5
0
        public static bool Redo(KPage page)
        {
            if (!history.ContainsKey(page))
            {
                return(false);
            }
            if (history[page].Current >= history[page].Versions.Count - 1)
            {
                return(false);
            }

            page.LoadFromString(E.GetString(history[page].Versions[++history[page].Current].Data), Program.MainLog);
            SetButtonVisibility(page);
            return(true);
        }
Ejemplo n.º 6
0
        public static async Task <bool> UpdateImage(KPage page)
        {
            SizeF pageSize = page.Format.GetPixelSize();

            using (Bitmap bmp = new Bitmap((int)pageSize.Width, (int)pageSize.Height))
            {
                MemoryStream stream = null;
                Task         t      = new Task(() =>
                {
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        g.Clear(Color.White);
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        var r           = g.GetRenderer();
                        lock (page)
                        {
                            page.DrawBackground(r);
                            page.Draw(r);
                        }
                    }
                    stream = new MemoryStream();
                    bmp.Save(stream, ImageFormat.Bmp);
                });
                t.Start();
                await t;
                uploadFinished = false;
                string url = $"{host}Load/{castId}";
                client.UploadDataAsync(new Uri(url), "post", stream.ToArray());
                while (!uploadFinished)
                {
                    await Task.Delay(10);
                }
                Program.MainLog.AddLong(0, MessageType.MSG, $"Uploading image",
                                        $"Url: {url}\nImageSize: {stream.Length}\nError: {error?.Message}");
                stream.Close();
                stream.Dispose();
                if (error == null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 7
0
        private void btnDeletePage_Click(object sender, EventArgs e)
        {
            if (doc.Pages.Count <= 1)
            {
                Dialogues.MsgBox.ShowOk("Action.cantDelLast");
            }
            else
            {
                if (Dialogues.MsgBox.ShowYesNo("Action.delPage?"))
                {
                    int currentInd = -1;
                    for (int i = 0; i < doc.Pages.Count; i++)
                    {
                        if (doc.Pages[i] == inkControl1.Page)
                        {
                            currentInd = i;
                            break;
                        }
                    }

                    if (currentInd >= 0)
                    {
                        KPage page = doc.Pages[currentInd];
                        doc.Pages.RemoveAt(currentInd);
                        page.Dispose();

                        currentInd--;
                        if (currentInd < 0)
                        {
                            currentInd = 0;
                        }

                        inkControl1.LoadPage(doc.Pages[currentInd]);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 static string pageInfo(KPage page)
 {
     return("" + page.Version + "#" + page.Name);
 }
Ejemplo n.º 9
0
 private void InkControl1_PageLoaded(object sender, KPage e)
 {
     HistoryManager.SetButtonVisibility(e);
 }
Ejemplo n.º 10
0
 public void RemovePage(KPage page)
 {
     Pages.Remove(page);
     page.Dispose();
 }
Ejemplo n.º 11
0
        public bool LoadDocument(string path, MessageLog log)
        {
            log?.Add(MessageType.MSG, "Loading File '{0}'", path);
            DirectoryInfo dir = TmpManager.GetTmpDir();

            if (path != null)
            {
                ZipFile zip = new ZipFile(path);
                if (dir.Exists)
                {
                    dir.RemoveAll();
                }
                try
                {
                    zip.ExtractAll(dir.FullName);
                }
                catch (BadPasswordException)
                {
                    Dialogues.PasswordDialog dialog = new Dialogues.PasswordDialog();
                    var res = dialog.ShowDialog(out string pw, delegate(string _password)
                    {
                        try
                        {
                            zip.Password = _password;
                            zip.ExtractAll(dir.FullName);
                            return(true);
                        }
                        catch (BadPasswordException)
                        {
                            return(false);
                        }
                    });
                    if (res == DialogResult.Cancel)
                    {
                        return(false);
                    }
                }
            }
            FileInfo    docFile = new FileInfo(dir + "\\document.kritzel");
            XmlReader   reader  = XmlReader.Create(docFile.FullName);
            XmlDocument doc     = new XmlDocument();

            doc.Load(reader);
            reader.Close();
            XmlNode root      = doc.LastChild;
            XmlNode pagesNode = root.GetNode("Pages");
            //Bitmap[] bgrs = new Bitmap[0];
            PdfDocument pdfDoc  = null;
            bool        loadPdf = false;

            if (File.Exists(dir + "\\.pdf"))
            {
                //bgrs = MupdfSharp.PageRenderer.Render(dir + "\\.pdf", Dialogues.PDFImporter.PAGETHEIGHTPIXEL);
                pdfDoc  = PdfSharp.Pdf.IO.PdfReader.Open(dir + "\\.pdf", PdfDocumentOpenMode.Modify | PdfDocumentOpenMode.Import);
                loadPdf = true;
            }
            int ind = 1;

            foreach (XmlNode xmlPage in pagesNode.GetNodes("Page"))
            {
                string src  = xmlPage.Attributes.GetNamedItem("src").InnerText;
                string text = File.ReadAllText(dir.FullName + "\\" + src);
                KPage  page = new KPage(this);
                log?.Add(MessageType.MSG, "Loading Page {0}", ind++);
                page.LoadFromString(text, log);
                int pdfInd;
                int.TryParse(xmlPage.Attributes["pdf"].Value, out pdfInd);
                if (pdfInd >= 0 && loadPdf)
                {
                    //page.BackgroundImage = new Renderer.Image(bgrs[pdfInd]);
                    page.OriginalPage  = pdfDoc.Pages[pdfInd];
                    page.PdfRenderPath = TmpManager.NewFilename(TmpManager.GetTmpDir() + "\\render", "page", ".png");
                }
                Pages.Add(page);
            }

            var defForm = doc.GetElementsByTagName("DefaultFormat");

            if (defForm.Count > 0)
            {
                DefaultFormat = defForm[0].InnerText;
            }

            if (loadPdf)
            {
                pdfDoc.Close();
                pdfDoc.Dispose();
            }

            this.FilePath = path;
            SetCurrentStateAsSaved();
            return(true);
        }