public DocumentationGenerator Download(DocumentType docType, string fileName, VideoForUser video) { DocumentationGenerator documentGenerator = DocumentationGenerator.Create(_domain, _fontPath, docType, fileName); var fields = new List <string> { "Отрывок текста" }; if (video.HasAnyTranslation) { fields.Add("Перевод"); } var tableData = new TableData(fields.Count, false); tableData.AddHeader(fields); foreach (var sentence in video.Sentences) { fields = new List <string> { sentence.Item1 }; if (video.HasTranslation(sentence)) { fields.Add(sentence.Item2); } tableData.AddRow(fields); } documentGenerator.AddHeader(string.Format("Текст из видео «{0}»", video.Title)); documentGenerator.AddTable(tableData); return(documentGenerator); }
public DocumentationGenerator Download(DocumentType docType, string fileName, Dictionary <KnowledgeDataType, List <GeneratedKnowledgeItem> > generatedItems) { DocumentationGenerator documentGenerator = DocumentationGenerator.Create(_domain, _fontPath, docType, fileName); var tables = new Dictionary <string, TableData>(); foreach (KnowledgeDataType knowledgeDataType in generatedItems.Keys) { var tableData = new TableData(2, true); string tableHeader = GetTableHeader(knowledgeDataType); if (!string.IsNullOrEmpty(tableHeader)) { tableData.AddHeader(tableHeader, "Перевод"); string subHeader = GetHeader(knowledgeDataType); tables.Add(subHeader, tableData); } List <GeneratedKnowledgeItem> items = generatedItems[knowledgeDataType]; foreach (GeneratedKnowledgeItem item in items) { var sourceTranslation = (SourceWithTranslation)item.ParsedData; tableData.AddRow(sourceTranslation.Source.Text, sourceTranslation.Translation.Text); } } if (string.IsNullOrEmpty(Header)) { Header = "Генератор знаний"; } documentGenerator.AddHeader(Header, false); foreach (var pair in tables) { documentGenerator.AddHeader(pair.Key); documentGenerator.AddTable(pair.Value); } return(documentGenerator); }
public DocumentationGenerator Download(DocumentType docType, string fileName, RepresentationForUser representationForUser) { DocumentationGenerator documentGenerator = DocumentationGenerator.Create(_domain, _fontPath, docType, fileName); var tableData = new TableData(2, true); tableData.AddHeader("Слово", "Перевод"); foreach (RepresentationAreaForUser area in representationForUser.Areas) { tableData.AddRow(area.Source.Text, area.Translation.Text); } documentGenerator.AddHeader(string.Format("Визуальный словарь на тему «{0}»", representationForUser.Title)); documentGenerator.AddTable(tableData); return(documentGenerator); }
public DocumentationGenerator Download(DocumentType docType, string fileName, List <SourceWithTranslation> elemsWithTranslations) { DocumentationGenerator documentGenerator = DocumentationGenerator.Create(_domain, _fontPath, docType, fileName); var tableData = new TableData(2, true); tableData.AddHeader(TableHeader, "Перевод"); foreach (SourceWithTranslation elem in elemsWithTranslations) { tableData.AddRow(elem.Source.Text, elem.Translation.Text); } documentGenerator.AddHeader(Header); documentGenerator.AddTable(tableData); return(documentGenerator); }
public DocumentationGenerator Download(DocumentType docType, string fileName, List <SourceWithTranslation> words) { DocumentationGenerator documentGenerator = DocumentationGenerator.Create(_domain, _fontPath, docType, fileName); var tableData = new TableData(2, true); tableData.AddHeader("Слово", "Перевод"); foreach (SourceWithTranslation word in words) { tableData.AddRow(word.Source.Text, word.Translation.Text); } if (string.IsNullOrEmpty(Header)) { Header = "Минилекс Гуннемарка"; } documentGenerator.AddHeader(Header); documentGenerator.AddTable(tableData); return(documentGenerator); }
public byte[] Generate(LanguageShortName from, LanguageShortName to, HashSet <long> visualDictionariesIds) { var languagesQuery = new LanguagesQuery(from, to); UserLanguages userLanguages = languagesQuery.GetLanguagesByShortNames(from, to); var representationsQuery = new RepresentationsQuery(userLanguages.From.Id); List <RepresentationForUser> allRepresentations = representationsQuery.GetBought(userLanguages, visualDictionariesIds); PdfGenerator commonPdfGenerator = allRepresentations.Count > 1 ? new PdfGenerator(_fontPath, _domain, "Все визуальные словари") : null; var zipKey = GetZipKey(allRepresentations, @from, to); var result = _cache.Get(zipKey); if (result != null) { return(result); } var painter = new Painter(); var partImageCreator = new PartImageCreator(painter); foreach (RepresentationForUser representation in allRepresentations) { var tableData = new TableData(3, true); tableData.AddHeader(string.Empty, "Слово", "Перевод"); string title = representation.Title; /*if (pictureName != "Лицо" /*&& pictureName != "Человек"#1#) { * continue; * }*/ var byteStream = new MemoryStream(representation.Image); Image image = Image.FromStream(byteStream); var wordsWriter = new WordsWriter(painter, image.Width, image.Height); foreach (RepresentationAreaForUser area in representation.Areas) { Point leftCorner = area.LeftUpperCorner; Point rightCorner = area.RightBottomCorner; string partKey = representation.Id + "_part_" + area.Id + "_" + representation.SortInfo.LastModified.Ticks + "_" + from + "_" + to + ".jpeg"; byte[] partImageBytes = _cache.Get(partKey); if (partImageBytes == null) { PartImageData partImageData = partImageCreator.CutImage(leftCorner, rightCorner, image); partImageBytes = ImageToBytes(partImageData.Bitmap); WriteToCache(partKey, partImageBytes); } tableData.AddRow(new[] { TableDataCell.CreateImage(partImageBytes), TableDataCell.CreateText(area.Source.Text), TableDataCell.CreateText(area.Translation.Text) }); wordsWriter.AddRectangle(leftCorner, rightCorner, area); } string fullKey = representation.Id + "_" + representation.SortInfo.LastModified.Ticks + "_" + from + "_" + to + ".jpeg"; byte[] imageResult = _cache.Get(fullKey); if (imageResult == null) { Image imageWithSign = wordsWriter.GetImageWithSigns(image); imageResult = ImageToBytes(imageWithSign); WriteToCache(fullKey, imageResult); } var pdfFileName = title + ".pdf"; string pdfKey = representation.Id + "_" + representation.SortInfo.LastModified.Ticks + "_" + from + "_" + to + "_" + pdfFileName; byte[] pdfContent = _cache.Get(pdfKey); if (pdfContent == null) { var pdfGenerator = new PdfGenerator(_fontPath, _domain, string.Format( "Визуальный словарь на тему {0}", title)); WriteDataToPdf(pdfGenerator, title, imageResult, tableData); pdfContent = pdfGenerator.GetAsBytes(); WriteToCache(pdfKey, pdfContent); } _zipCompressor.AddFileToArchive(pdfFileName, pdfContent); if (commonPdfGenerator != null) { WriteDataToPdf(commonPdfGenerator, title, imageResult, tableData); commonPdfGenerator.NewPage(); } } if (commonPdfGenerator != null) { WritePdfToArchive(commonPdfGenerator, "Всё в одном файле.pdf"); } result = _zipCompressor.GetArchive(); WriteToCache(zipKey, result); return(result); }