Пример #1
0
        private OpenXmlElement ConvertLinkInline(LinkInline linkInline, bool isBoldInherited = false, bool isItalicInherited = false)
        {
            if (linkInline.IsImage)
            {
                var explicitAbsoluteImagePath = GetExplicitAbsoluteImagePath(linkInline.Url, BaseFolderPathForRelativePath);
                var relationshipId            = AddImagePartFromFile(explicitAbsoluteImagePath);

                // At this time, temporary uses the original image dimension.
                // In later, adjust the image dimension using the page settings and inherited indentation.
                (var originalImageWidthInch, var originalImageHeightInch) = Manipulator.GetImageDimensionInInch(relationshipId);
                var originalImageWidthEmu  = WordDocumentManipulator.UnitConverter.InchToEmu(originalImageWidthInch);
                var originalImageHeightEmu = WordDocumentManipulator.UnitConverter.InchToEmu(originalImageHeightInch);

                var fileName = Path.GetFileName(explicitAbsoluteImagePath);
                var altText  = GetLinkText(linkInline);
                return(Manipulator.ElementCreator.CreateImageElement(relationshipId, (long)originalImageWidthEmu, (long)originalImageHeightEmu, fileName, altText));
            }
            else
            {
                var linkText = GetLinkText(linkInline);

                var hyperlinkUri            = GetLinkTargetUri(linkInline.Url);
                var hyperlinkRelationshipId = Manipulator.AddHyperlinkRelationship(hyperlinkUri);

                var styleId = UserSettingStyleMap.GetStyleId(UserSettingStyleMap.StyleMapKeyType.Hyperlink, null);
                return(Manipulator.ElementCreator.CreateHyperlinkElement(linkText, hyperlinkRelationshipId, isBoldInherited, isItalicInherited, styleId));
            }
        }