Exemplo n.º 1
0
        private string CaptionSpecificPath(CaptionElement caption, string pathPrefix, string pathSuffix)
        {
            string startTime = caption.BeginText ?? "00:00:00"; //if null using "00:00:00"
            string endTime   = caption.EndText ?? "00:00:00";   //if null using "00:00:00"

            return(pathPrefix + startTime + "-" + endTime + pathSuffix);
        }
        private StackPanel NewPanel(StackPanel parent, ref double offset, CaptionElement element, TextAlignment align)
        {
            StackPanel p = new StackPanel
            {
                Orientation = Orientation.Horizontal
            };

            switch (align)
            {
            case TextAlignment.Center:
                p.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                break;

            case TextAlignment.Right:
                p.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                break;

            case TextAlignment.Left:
                p.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                break;

            default:        //TextAlignment.Justify:
                p.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                break;
            }
            parent.Children.Add(p);
            offset = 0;
            return(p);
        }
        public static void Run()
        {
            // ExStart:CreateStructureElements
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Create Pdf Document
            Document document = new Document();

            // Get Content for work with TaggedPdf
            ITaggedContent taggedContent = document.TaggedContent;

            // Set Title and Language for Documnet
            taggedContent.SetTitle("Tagged Pdf Document");
            taggedContent.SetLanguage("en-US");

            // Create Grouping Elements
            PartElement       partElement       = taggedContent.CreatePartElement();
            ArtElement        artElement        = taggedContent.CreateArtElement();
            SectElement       sectElement       = taggedContent.CreateSectElement();
            DivElement        divElement        = taggedContent.CreateDivElement();
            BlockQuoteElement blockQuoteElement = taggedContent.CreateBlockQuoteElement();
            CaptionElement    captionElement    = taggedContent.CreateCaptionElement();
            TOCElement        tocElement        = taggedContent.CreateTOCElement();
            TOCIElement       tociElement       = taggedContent.CreateTOCIElement();
            IndexElement      indexElement      = taggedContent.CreateIndexElement();
            NonStructElement  nonStructElement  = taggedContent.CreateNonStructElement();
            PrivateElement    privateElement    = taggedContent.CreatePrivateElement();

            // Create Text Block-Level Structure Elements
            ParagraphElement paragraphElement = taggedContent.CreateParagraphElement();
            HeaderElement    headerElement    = taggedContent.CreateHeaderElement();
            HeaderElement    h1Element        = taggedContent.CreateHeaderElement(1);

            // Create Text Inline-Level Structure Elements
            SpanElement  spanElement  = taggedContent.CreateSpanElement();
            QuoteElement quoteElement = taggedContent.CreateQuoteElement();
            NoteElement  noteElement  = taggedContent.CreateNoteElement();

            // Create Illustration Structure Elements
            FigureElement  figureElement  = taggedContent.CreateFigureElement();
            FormulaElement formulaElement = taggedContent.CreateFormulaElement();

            // Methods are under development
            ListElement      listElement      = taggedContent.CreateListElement();
            TableElement     tableElement     = taggedContent.CreateTableElement();
            ReferenceElement referenceElement = taggedContent.CreateReferenceElement();
            BibEntryElement  bibEntryElement  = taggedContent.CreateBibEntryElement();
            CodeElement      codeElement      = taggedContent.CreateCodeElement();
            LinkElement      linkElement      = taggedContent.CreateLinkElement();
            AnnotElement     annotElement     = taggedContent.CreateAnnotElement();
            RubyElement      rubyElement      = taggedContent.CreateRubyElement();
            WarichuElement   warichuElement   = taggedContent.CreateWarichuElement();
            FormElement      formElement      = taggedContent.CreateFormElement();

            // Save Tagged Pdf Document
            document.Save(dataDir + "StructureElements.pdf");
            // ExEnd:CreateStructureElements
        }
Exemplo n.º 4
0
 public void SaveCaptionCommentsAudio(CaptionElement caption, ZipFile zip, string zipFolder = "")
 {
     if ((caption != null) && caption.HasCommentsAudio())
     {
         zip.AddEntry(
             zipFolder + CaptionCommentsAudioPath(caption, caption.GetCommentsAudio().Kind.GetExtension()),
             new WriteDelegate((entryName, stream) => { caption.SaveCommentsAudio(stream); }));
     }
 }
Exemplo n.º 5
0
 public void SaveCaptionExtraData(CaptionElement caption, ZipFile zip, string zipFolder = "")
 {
     if ((caption != null) && caption.HasExtraData())
     {
         zip.AddEntry(
             zipFolder + CaptionExtraDataPath(caption),
             new WriteDelegate((entryName, stream) => { caption.SaveExtraData(stream); }));
     }
 }
Exemplo n.º 6
0
        public void LoadCaptionExtraData(CaptionElement caption, ZipFile zip, string zipFolder = "")
        {
            ZipEntry entry = zip[zipFolder + CaptionExtraDataPath(caption)];

            if (entry != null)
            {
                caption.LoadExtraData(entry.OpenReader(), (int)entry.UncompressedSize);
            }
        }
        private UIElement RenderElement(CaptionElement element)
        {
            StackPanel parent = null;

            try
            {
                parent = new StackPanel
                {
                    Background          = GetCachedBrush(element.CurrentStyle.BackgroundColor),
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch
                };


                var textAlignment = element.CurrentStyle.TextAlign;

                double     offset = 0;
                StackPanel p      = NewPanel(parent, ref offset, element, textAlignment);
                RenderElementRecurse(parent, ref p, element, ref offset, textAlignment);

#if !WINDOWS_PHONE && !SILVERLIGHT3 && NOTUSED
                foreach (StackPanel stack in parent.Children)
                {
                    double baseline = 0;
                    foreach (Border b in stack.Children)
                    {
                        TextBlock tb = b.Child as TextBlock;
                        if (tb != null && tb.BaselineOffset > baseline)
                        {
                            baseline = tb.ActualHeight - tb.BaselineOffset;
                        }
                    }
                    foreach (Border b in stack.Children)
                    {
                        TextBlock tb = b.Child as TextBlock;
                        if (tb != null)
                        {
                            tb.Margin = new Thickness(0, 0, 0, baseline - (tb.ActualHeight - tb.BaselineOffset));
                        }
                    }
                }
#endif
            }
            catch (Exception)
            {
                //TODO: Respond to errors
            }

            return(parent);
        }
Exemplo n.º 8
0
        public void LoadCaptionCommentsAudio(CaptionElement caption, ZipFile zip, string zipFolder = "")
        {
            string path = CaptionCommentsAudioPath(caption);

            string   fileExtension = AudioStreamKindUtils.EXTENSION_WAV;
            ZipEntry entry         = zip[zipFolder + path + fileExtension];

            if (entry == null)
            {
                fileExtension = AudioStreamKindUtils.EXTENSION_MP3;
                entry         = zip[zipFolder + path + fileExtension];
            }

            if (entry != null)
            {
                caption.LoadCommentsAudio(entry.OpenReader(), fileExtension, (int)entry.UncompressedSize);
            }
        }
        private void Player_DataReceived(object sender, DataReceivedInfo e)
        {
            if (IsCaptionStream(e.StreamAttributes))
            {
                try
                {
                    var stream   = new MemoryStream(e.Data);
                    var text     = new StreamReader(stream).ReadToEnd();
                    var duration = e.DataChunk.Duration != TimeSpan.Zero
                                        ? e.DataChunk.Duration
                                        : TimeSpan.FromMilliseconds(2002);

                    if (_captionRegion.Begin == TimeSpan.MinValue || _captionRegion.Begin > e.DataChunk.Timestamp)
                    {
                        _captionRegion.Begin = e.DataChunk.Timestamp;
                    }

#if SILVERLIGHT3
                    if (!SystemExtensions.IsNullOrWhiteSpace(text))
#else
                    if (!string.IsNullOrWhiteSpace(text))
#endif
                    {
                        var caption = new CaptionElement
                        {
                            Content = text,
                            Begin   = e.DataChunk.Timestamp,
                            End     = e.DataChunk.Timestamp.Add(duration)
                        };

                        _captionRegion.Children.Add(caption);
                    }
                }
                catch (Exception err)
                {
                    Debug.WriteLine(err.Message);
                }
            }
        }
        private void RenderElementRecurse(StackPanel parent, ref StackPanel p, CaptionElement element, ref double offset, TextAlignment align)
        {
            if (element.IsActiveAtPosition(_mediaPosition) && element.CurrentStyle.Display == System.Windows.Visibility.Visible)
            {
                if (element.CaptionElementType == TimedTextElementType.Text)
                {
                    var text = element.Content != null?element.Content.ToString() : string.Empty;

                    offset = WrapElement(parent, ref p, offset, text, element, align);
                }
                else if (element.CaptionElementType == TimedTextElementType.Container)
                {
                    foreach (CaptionElement child in element.Children)
                    {
                        RenderElementRecurse(parent, ref p, child, ref offset, align);
                    }
                }
                else if (element.CaptionElementType == TimedTextElementType.LineBreak)
                {
                    p = NewPanel(parent, ref offset, element, align);
                }
            }
        }
        private void CreatePlaylist()
        {
            var playlistItem = new Core.Media.PlaylistItem();

            playlistItem.MediaSource    = new Uri("http://ecn.channel9.msdn.com/o9/content/smf/smoothcontent/elephantsdream/Elephants_Dream_1024-h264-st-aac.ism/manifest");
            playlistItem.DeliveryMethod = DeliveryMethods.AdaptiveStreaming;

            var region = new CaptionRegion();

            playlistItem.Captions.Add(region);

            var caption1 = new CaptionElement
            {
                Begin   = TimeSpan.Zero,
                End     = TimeSpan.FromSeconds(10),
                Content = "This marker should display from 00:00:00 to 00:00:10 and the text should be red."
            };

            caption1.Style.Color          = Colors.Red;
            caption1.Style.FontSize.Unit  = LengthUnit.Pixel;
            caption1.Style.FontSize.Value = 15;
            region.Children.Add(caption1);

            var caption2 = new CaptionElement
            {
                Begin   = TimeSpan.FromSeconds(20),
                End     = TimeSpan.FromSeconds(30),
                Content = "This marker should display from 00:00:20 to 00:00:30 and the text should be yellow."
            };

            caption2.Style.Color          = Colors.Yellow;
            caption2.Style.FontSize.Unit  = LengthUnit.Pixel;
            caption2.Style.FontSize.Value = 15;
            region.Children.Add(caption2);

            player.Playlist.Add(playlistItem);
        }
Exemplo n.º 12
0
 //--------------------------------------------------
 //	IHTMLTable
 //--------------------------------------------------
 //#>>delete
 public CaptionElement createCaption()
 {
     return(CaptionElement.FromObj(this.Invoke("createCaption")));
 }
Exemplo n.º 13
0
        public static new Element FromObj(object instance)
        {
            if (instance == null)
            {
                return(null);
            }
            try{
                string tagUrn  = (string)GetProperty(instance, "tagUrn");
                string tagName = (string)GetProperty(instance, "tagName");
                if (tagUrn == null || tagUrn == "")
                {
                    switch (tagName.ToLower())
                    {
                    case "!":                       return(CommentElement.FromObj(instance));

                    case "a":                       return(AElement.FromObj(instance));

                    case "area":            return(AreaElement.FromObj(instance));

                    case "base":            return(BaseElement.FromObj(instance));

                    case "basefont":        return(BaseFontElement.FromObj(instance));

                    case "bgsound":         return(BgsoundElement.FromObj(instance));

                    case "address":
                    case "pre":
                    case "center":
                    case "listing":
                    case "xmp":
                    case "plaintext":
                    case "blockquote":      return(BlockElement.FromObj(instance));

                    case "body":            return(BodyElement.FromObj(instance));

                    case "br":                      return(BrElement.FromObj(instance));

                    case "button":          return(ButtonElement.FromObj(instance));

                    case "dd":                      return(DdElement.FromObj(instance));

                    case "div":                     return(DivElement.FromObj(instance));

                    case "dl":                      return(DlElement.FromObj(instance));

                    case "dt":                      return(DtElement.FromObj(instance));

                    case "embed":           return(EmbedElement.FromObj(instance));

                    case "fieldset":        return(FieldsetElement.FromObj(instance));

                    case "font":            return(FontElement.FromObj(instance));

                    case "form":            return(FormElement.FromObj(instance));

                    case "frame":           return(FrameElement.FromObj(instance));

                    case "frameset":        return(FramesetElement.FromObj(instance));

                    case "head":            return(HeadElement.FromObj(instance));

                    case "h1":
                    case "h2":
                    case "h3":
                    case "h4":
                    case "h5":
                    case "h6":
                        return(HnElement.FromObj(instance));

                    case "hr":                      return(HrElement.FromObj(instance));

                    case "html":            return(HtmlElement.FromObj(instance));

                    case "iframe":          return(IframeElement.FromObj(instance));

                    case "img":                     return(ImgElement.FromObj(instance));

                    case "input":           return(InputElement.FromObj(instance));

                    case "isindex":         return(IsindexElement.FromObj(instance));

                    case "legend":          return(LegendElement.FromObj(instance));

                    case "label":           return(LabelElement.FromObj(instance));

                    case "li":                      return(LiElement.FromObj(instance));

                    case "link":            return(LinkElement.FromObj(instance));

                    case "map":                     return(MapElement.FromObj(instance));

                    case "marquee":         return(MarqueeElement.FromObj(instance));

                    case "meta":            return(MetaElement.FromObj(instance));

                    case "nextid":          return(NextidElement.FromObj(instance));

                    case "noembed":
                    case "noframes":
                    case "nolayer":
                    case "noscript":        return(NoshowElement.FromObj(instance));

                    case "applet":
                    case "object":          return(ObjectElement.FromObj(instance));

                    case "ol":                      return(OlElement.FromObj(instance));

                    case "optgroup":
                    case "option":          return(OptionElement.FromObj(instance));

                    case "p":                       return(PElement.FromObj(instance));

                    case "param":           return(ParamElement.FromObj(instance));

                    case "i":
                    case "u":
                    case "b":
                    case "q":
                    case "s":
                    case "strong":
                    case "del":
                    case "strike":
                    case "em":
                    case "small":
                    case "big":
                    case "ruby":
                    case "rp":
                    case "sub":
                    case "sup":
                    case "acronym":
                    case "bdo":
                    case "cite":
                    case "dfn":
                    case "ins":
                    case "code":
                    case "kbd":
                    case "samp":
                    case "var":
                    case "nobr":            return(PhraseElement.FromObj(instance));

                    case "script":          return(ScriptElement.FromObj(instance));

                    case "select":          return(SelectElement.FromObj(instance));

                    case "span":            return(SpanElement.FromObj(instance));

                    case "style":           return(StyleElement.FromObj(instance));

                    case "caption":         return(CaptionElement.FromObj(instance));

                    case "td":
                    case "th":                      return(TableCellElement.FromObj(instance));

                    case "table":           return(TableElement.FromObj(instance));

                    case "colgroup":
                    case "col":                     return(ColElement.FromObj(instance));

                    case "tr":                      return(TrElement.FromObj(instance));

                    case "thead":
                    case "tbody":
                    case "tfoot":           return(TableSectionElement.FromObj(instance));

                    case "textarea":        return(TextAreaElement.FromObj(instance));

                    case "wbr": return(TextElement.FromObj(instance));

                    case "title":           return(TitleElement.FromObj(instance));

                    case "dir":
                    case "menu":
                    case "ul":                      return(UlElement.FromObj(instance));
                        // optionbutton ?
                        // spanflow ?
                        // default:			return UnknownElement.FromObj(instance);
                    }
                }
            }catch {
                // IHTMLElement でない可能性
            }

            return(new Element(instance));
        }
Exemplo n.º 14
0
 private string CaptionAudioPath(CaptionElement caption, string fileExtension = "") //note: do not change ""
 {
     return(CaptionSpecificPath(caption, "/Audio/", fileExtension));
 }
Exemplo n.º 15
0
 private string CaptionExtraDataPath(CaptionElement caption)
 {
     return(CaptionSpecificPath(caption, "/ExtraData/", ".xml"));
 }
        private double WrapElement(StackPanel parent, ref StackPanel p, double offset, string text, CaptionElement element, TextAlignment align, bool directionApplied = false)
        {
            if (text == null || text == "")
            {
                return(offset);
            }

            var    effectiveSize = this.GetEffectiveSize();
            var    style         = element.CurrentStyle;
            var    panelSize     = style.Extent.ToPixelSize(effectiveSize);
            double panelWidth    = panelSize.Width;
            double panelHeight   = panelSize.Height;

            if (style.Direction == Direction.RightToLeft && !directionApplied)
            {
                text = new string(text.ToCharArray().Reverse().ToArray());
            }

            double    height    = style.FontSize.Unit == LengthUnit.PixelProportional || style.FontSize.Unit == LengthUnit.Cell ? effectiveSize.Height : panelHeight;
            TextBlock textblock = GetStyledTextblock(style, panelWidth, height, false);

            SetContent(textblock, text);

            Border border = new Border();

            border.Background = GetCachedBrush(style.BackgroundColor);
            FrameworkElement contentElement;

            double outlineWidth = style.OutlineWidth.ToPixelLength(effectiveSize.Height);

            if (outlineWidth > 0)
            {
                Grid cnv = new Grid();

                // do outline image up and to left
                TextBlock tb2 = GetStyledTextblock(style, panelWidth, height, true);
                SetContent(tb2, text);
                cnv.Children.Add(tb2);
                tb2.RenderTransform = new TranslateTransform()
                {
                    X = -1, Y = -1
                };

                // do outline image down and to right
                tb2 = GetStyledTextblock(style, panelWidth, height, true);
                SetContent(tb2, text);
                cnv.Children.Add(tb2);
                tb2.RenderTransform = new TranslateTransform()
                {
                    X = 1, Y = 1
                };

                // do outline image up and to right
                tb2 = GetStyledTextblock(style, panelWidth, height, true);
                SetContent(tb2, text);
                cnv.Children.Add(tb2);
                tb2.RenderTransform = new TranslateTransform()
                {
                    X = 1, Y = -1
                };

                // do outline image down and to left
                tb2 = GetStyledTextblock(style, panelWidth, height, true);
                SetContent(tb2, text);
                cnv.Children.Add(tb2);
                tb2.RenderTransform = new TranslateTransform()
                {
                    X = -1, Y = 1
                };

                // add the main text
                cnv.Children.Add(textblock);

                // add the border
                contentElement = cnv;
            }
            else
            {
                contentElement = textblock;
            }

            border.Child = contentElement;
            p.Children.Add(border);

            string head         = text;
            string tail         = string.Empty;
            double elementWidth = textblock.GetEffectiveWidth();

            if (offset + elementWidth > panelSize.Width && style.WrapOption == TextWrapping.Wrap)
            {
                if (text.Length > 0 && text.IndexOf(' ') < 0)
                {
                    if (offset != 0 && elementWidth < panelSize.Width)
                    {
                        p.Children.Remove(border);
                        p = NewPanel(parent, ref offset, element, align);
                        return(WrapElement(parent, ref p, 0, text, element, align, true));
                    }
                    int idx = text.Length - 1;
                    head = text.Substring(0, idx);
                    tail = text.Substring(idx);
                    SetAllContent(contentElement, head);
                    while (offset + textblock.GetEffectiveWidth() > panelSize.Width)
                    {
                        idx--;
                        head = text.Substring(0, idx);
                        tail = text.Substring(idx);
                        SetAllContent(contentElement, head);
                        p.UpdateLayout();
                    }
                    p = NewPanel(parent, ref offset, element, align);
                    return(WrapElement(parent, ref p, offset, tail, element, align, true));
                }
                while (offset + textblock.GetEffectiveWidth() > panelSize.Width)
                {
                    int idx = head.LastIndexOf(' ');
                    if (idx < 0)
                    {
                        SetAllContent(contentElement, text);
                        return(0);
                    }
                    else
                    {
                        tail = text.Substring(idx + 1);
                        head = text.Substring(0, idx);
                    }
                    SetAllContent(contentElement, head);
                }
                p = NewPanel(parent, ref offset, element, align);
                return(WrapElement(parent, ref p, offset, tail, element, align, true));
            }
            else
            {
                offset += elementWidth;
                return(offset);
            }
        }