如何在选择中创建淡入效果?

时间:2017-03-29 14:21:39

标签: libreoffice-calc libreoffice-basic

关于宏,很少有人使用Impress(没有宏记录,没有Python脚本,只有Basic等),而且样本很少。

没有示例如何创建“手动”文本动画。我找到了一个here(6岁)并且有很多信息。

到目前为止,我已经设法(1)扫描已经存在的文本动画“fadein”(2)扫描所有其他文本动画,然后将它们删除,用“fadein”的克隆替换它们动画:

sub MyFunction
    ' --------------------------------------------------------------------
    ' (1) scan for a text animation "fadein" that is already there
    effectNodeFadeIn = Null
    doc = ThisComponent
    numSlides = doc.getDrawPages().getCount()
    slide = doc.drawPages(numSlides-1)

    mainSequence = getMainSequence(slide)    
    clickNodes = mainSequence.createEnumeration()
    while clickNodes.hasMoreElements() and IsNull(effectNodeFadeIn)
        clickNode = clickNodes.nextElement()

        groupNodes = clickNode.createEnumeration()
        while groupNodes.hasMoreElements() and IsNull(effectNodeFadeIn)
            groupNode = groupNodes.nextElement()

            effectNodes = groupNode.createEnumeration()
            while effectNodes.hasMoreElements() and IsNull(effectNodeFadeIn)
                effectNode = effectNodes.nextElement()
                ' ICIC

                if effectNode.ImplementationName = "animcore::ParallelTimeContainer" then
                    if hasUserDataKey(effectNode, "preset-id") then
                        v = getUserDataValue(effectNode, "preset-id")
                        if v = "ooo-entrance-fade-in" then ' ooo-entrance-appear
                            effectNodeFadeIn = effectNode
                        end if
                    end if
                end if
                ' useless loop just in case I need it:
                animNodes = effectNode.createEnumeration()
                while animNodes.hasMoreElements()
                    animNode = animNodes.nextElement()
                wend
            wend
        wend
    wend
    ' --------------------------------------------------------------------
    ' (2) scan for all other text animations, 
    ' and then remove them an replace them by a clone of the "fadein" animation
    if not IsNull(effectNodeFadeIn) then

        clickNodes = mainSequence.createEnumeration()
        while clickNodes.hasMoreElements()
            clickNode = clickNodes.nextElement()

            groupNodes = clickNode.createEnumeration()
            while groupNodes.hasMoreElements()
                groupNode = groupNodes.nextElement()

                effectNodes = groupNode.createEnumeration()
                while effectNodes.hasMoreElements()
                    effectNode = effectNodes.nextElement()
                    ' ICIC

                    if effectNode.ImplementationName = "animcore::ParallelTimeContainer" then
                        if hasUserDataKey(effectNode, "preset-id") then
                            v = getUserDataValue(effectNode, "preset-id")
                            if v <> "ooo-entrance-fade-in" then ' ooo-entrance-appear
                                groupNode.removeChild(effectNode)
                                n = effectNodeFadeIn.createClone()
                                groupNode.appendChild(n)

                                ' useless loop just in case I need it:
                                animNodes = effectNode.createEnumeration()
                                while animNodes.hasMoreElements()
                                    animNode = animNodes.nextElement()
                                wend
                            end if
                        end if

                    end if
                wend
            wend
        wend
    end if
end sub

function hasUserDataKey(node as Object, key as String) as Boolean
    for each data in node.UserData
        if data.Name = "node-type" then
            hasUserDataKey = True
            exit function
        end if
    next data
    hasUserDataKey = False
end function

function getUserDataValue(node as Object, key as String) as Variant
    for each data in node.UserData
        if data.Name = key then
            getUserDataValue = data.Value
            exit function
        end if
    next data
end function

当我克隆效果时,它仍然“链接”到原始文本,然后删除父级并替换为“fadein”文本。知道怎么纠正这个吗?

1 个答案:

答案 0 :(得分:0)

听起来您在形状中选择了文本,因此请使用以下基本代码:

Sub AddAnimation
    xTextCursor = ThisComponent.CurrentController.Selection(0)
    xText = xTextCursor.getText()
    xText.TextEffect = com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM
End Sub

或者在python中:

import uno
from com.sun.star.presentation.AnimationEffect import FADE_FROM_BOTTOM

def add_animation():
    oDoc = XSCRIPTCONTEXT.getDocument()
    xTextCursor = oDoc.CurrentController.Selection.getByIndex(0)
    xText = xTextCursor.getText()
    xText.TextEffect = FADE_FROM_BOTTOM

由于我不完全清楚的原因,结果是擦拭而不是淡入。

文档位于https://wiki.openoffice.org/wiki/Documentation/DevGuide/Drawings/Animations_and_Interactions。该页面中的ShapeHelper类在ShapeHelper.java中定义。