/// <summary> /// The odd one out, belongs to volume, not ref. But here we go... /// </summary> /// <param name="message"></param> /// <returns></returns> internal string EditVolumeTitle(EventData message) { // Need to call in order to not mess up stack var dummy = ArrayStuff.ExtractArrayFromIntPtr(message.SelectionRects, 1); var volume = m_DBService.SelectById <Volume>(LastHistory.VolumeId); // If no volume, warn and exit if (volume == null) { m_MessageBoxService.Show($"No volume found for {message.FilePath}.", "Volume not found"); return(null); } string title = message.Text.RemoveCRLF().RemoveDoubleSpace(); if (string.IsNullOrWhiteSpace(title.Trim())) { title = volume.Title; } var form = new Form_AddReference($"Volume title", title); if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel || string.IsNullOrWhiteSpace(form.Value)) { return(null); } string newTitle = form.Value; volume.Title = newTitle; m_DBService.InsertOrUpdate(volume); return(newTitle); }
public string AddReference <T>(EventData message) where T : Reference, new() { // Need to call in order to not mess up stack var dummy = ArrayStuff.ExtractArrayFromIntPtr(message.SelectionRects, 1); var volume = m_DBService.SelectById <Volume>(LastHistory.VolumeId); // Current volume var form = new Form_AddReference($"Add {new T().GetType().Name} title", message.Text); if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return(null); } T reference = new T { Id = Id.NewId(), Title = form.Value, VolumeId = volume.Id, PhysicalPage = message.StartPage, Glyph = message.StartGlyph, }; m_DBService.InsertOrUpdate(reference); return(reference.Title); }
public void ConvertArrayToString_NoRects_Valid() { // Given int[] rects = new int[0]; // When string res = ArrayStuff.ConvertArrayToString(rects); // Then Assert.That(res, Is.EqualTo("")); }
public void ConvertArrayToString_FourRects_Valid() { // Given int[] rects = new[] { 1, 2, 3, 4, 11, 22, 33, 44, 111, 222, 333, 444, 1111, 2222, 3333, 4444 }; // When string res = ArrayStuff.ConvertArrayToString(rects); // Then Assert.That(res, Is.EqualTo("1,2,3,4;11,22,33,44;111,222,333,444;1111,2222,3333,4444;")); }
public void ConvertArrayToString_OneRect_Valid() { // Given int[] rects = new[] { 1, 2, 3, 4 }; // When string res = ArrayStuff.ConvertArrayToString(rects); // Then Assert.That(res, Is.EqualTo("1,2,3,4;")); }
public RawCitation AddRawCitations(EventData message) { LastHistory = m_HistoryRepo.GetLastOpened(); // Our currently open file in Sumatra int[] rects = ArrayStuff.ExtractArrayFromIntPtr(message.SelectionRects, message.Len * 4); var volume = m_DBService.SelectById <Volume>(LastHistory.VolumeId); RawCitation raw = new RawCitation { Id = Id.NewId(), VolumeId = volume.Id, Fragment = message.Text, GlyphStart = message.StartGlyph, GlyphStop = message.StopGlyph, PageStop = message.StopPage, PageStart = message.StartPage, Date = DateTime.Now, Rectangles = ArrayStuff.ConvertPageAndArrayToString(message.StartPage, rects), }; m_DBService.InsertOrUpdate(raw); return(raw); }
public Page AddPage(EventData message) { // Need to call in order to not mess up stack var _ = ArrayStuff.ExtractArrayFromIntPtr(message.SelectionRects, 1); int decodedPage = message.StartPage; if (!string.IsNullOrEmpty(message.Text)) { try { string allowed = "0123456789"; string clean = ""; foreach (char c in message.Text) { if (allowed.Contains(c.ToString())) { clean += c; } } decodedPage = int.Parse(clean); } catch { } } bool valid = true; string formValue = decodedPage.ToString(); do { var form = new Form_AddReference($"{(valid? "" : "[Invalid] ")}Set page number", formValue); if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return(null); } try { decodedPage = int.Parse(form.Value.Trim()); valid = true; } catch { valid = false; formValue = form.Value; } } while (!valid); m_DBService.Delete <Page>($"`PhysicalPage`={message.StartPage}");// There can be only one (per page) Page page = new Page { Id = Id.NewId(), VolumeId = LastHistory.VolumeId, PhysicalPage = message.StartPage, Glyph = -1, Title = message.Text, PaginationStart = decodedPage }; m_DBService.InsertOrUpdate(page); return(page); }
public void RecreateTheWholeThing(ModelsForViewing vm, VolumeService volumeService) { string origFileName = vm.CurrentStorage.FilePath; string storageFilePath = System.IO.Path.Combine(m_UserSettingsService.StorageFolder, vm.CurrentStorage.StorageName); string newFileTmp = m_TempFileService.GetNewTmpFileName(vm.CurrentStorage.StorageName); //File.Copy(storageFilePath, tmpFileName, true); (int x, int y)offset = (volumeService.CurrentVolume.OffsetX, volumeService.CurrentVolume.OffsetY); PdfDocument pdfDoc = new PdfDocument(new PdfReader(origFileName), new PdfWriter(newFileTmp)); foreach (Citation cit in volumeService.Citations) { // Yeah, somtimes illegal citations end up in the database. if (cit.SelectionRects.Trim().Length < 5) { continue; } var cat = m_CategoryService.GetMainCategory(cit.Id); var citCat = m_CategoryService.GetMainCitationCategory(cit.Id); if (cat == null) { citCat.CategoryId = Id.Empty; } List <(int page, int[] rects)> pageRects = ArrayStuff.ConvertStringToPagesAndArrays(cit.SelectionRects); int firstPageNo = GetFirstPageFromPageRects(pageRects); Color color_highLight, color_underLine, color_margin = new DeviceRgb(n(255), n(255), n(255));; if (pageRects.Any()) { System.Drawing.Color ch, cu, cm; var colors = ColorStuff.ConvertStringToColors(cit.CitationColors); ch = (colors.Length >= 1) ? colors[0] : m_UserSettingsService.PdfHighLightColor; cu = (colors.Length >= 2) ? colors[1] : m_UserSettingsService.PdfUnderlineColor; cm = (colors.Length >= 3) ? colors[2] : m_UserSettingsService.PdfMarginBoxColor; color_highLight = new DeviceRgb(n(ch.R), n(ch.G), n(ch.B)); color_underLine = new DeviceRgb(n(cu.R), n(cu.G), n(cu.B)); color_margin = new DeviceRgb(n(cm.R), n(cm.G), n(cm.B)); foreach ((int page, int[] rects)pageRect in pageRects) { if (pageRect.rects.Count() < 4) // If no rects, for some reason... { continue; } //int currentPage = pageRects.First().page; int currentPage = pageRect.page; int currentRect = 0; bool notDone = true; do { PdfCanvas canvas1 = new PdfCanvas( pdfDoc.GetPage(currentPage).NewContentStreamBefore(), pdfDoc.GetPage(currentPage).GetResources(), pdfDoc); PdfCanvas canvas2 = new PdfCanvas( pdfDoc.GetPage(currentPage).NewContentStreamAfter(), pdfDoc.GetPage(currentPage).GetResources(), pdfDoc); Rectangle pageSize = pdfDoc.GetPage(firstPageNo).GetPageSize(); int pageHeight = (int)pageSize.GetHeight(); int pageWidth = (int)pageSize.GetWidth(); //canvas.SaveState(); canvas1.SetFillColor(color_highLight); canvas2.SetFillColor(color_underLine); do //(int i = 0; i < rects.Length; i += 4) { if (currentRect >= pageRect.rects.Length) // Sometime this is necessary, page rects are empty or broken. { break; } int x = pageRect.rects[currentRect] + offset.x; int y = pageHeight - pageRect.rects[currentRect + 1] - pageRect.rects[currentRect + 3] + offset.y; // Below text highlight canvas1.Rectangle(x, y, pageRect.rects[currentRect + 2], pageRect.rects[currentRect + 3]); canvas1.Fill(); // Above text underline canvas2.Rectangle(x, y, pageRect.rects[currentRect + 2], 1); canvas2.Fill(); if (currentRect + 5 > pageRect.rects.Length) { notDone = false; break; } // Detect page break int lastY = pageHeight - pageRect.rects[currentRect + 1] - pageRect.rects[currentRect + 3]; currentRect += 4; int newY = pageHeight - pageRect.rects[currentRect + 1] - pageRect.rects[currentRect + 3]; if (lastY < newY) { currentPage++; break; } } while (true); } while (notDone); } // Add annotation AddMarginBox(pdfDoc, null, firstPageNo, cit.Id.ToString(), cat.Code + $" [{citCat.Weight}]", cit.SelectionRects, color_margin, cit.MarginBoxSettings, offset); }// if pagerects.any } pdfDoc.Close(); // newFileTmp m_StorageHelperService.GetNextStorageFileName(vm.CurrentStorage); string newStoragePath = System.IO.Path.Combine(m_UserSettingsService.StorageFolder, vm.CurrentStorage.StorageName); int retries = 10; do { try { //File.Delete(storageFilePath); File.Copy(newFileTmp, newStoragePath); retries = 0; } catch { retries--; Thread.Sleep(500); } } while (retries > 0); File.Delete(newFileTmp); m_StorageHelperService.DeleteOldStorageFiles(newStoragePath); }