private void CreateAnimation(SlideInAnimation.SlieInDirection direction, AnimationChar animChar, float finalPosX) { //计算与字体相关的参数 int ascent = animChar.Font.FontFamily.GetCellAscent(animChar.Font.Style); int descent = animChar.Font.FontFamily.GetCellDescent(animChar.Font.Style); int emHeight = animChar.Font.FontFamily.GetEmHeight(animChar.Font.Style); float ascentF = ascent * animChar.Font.Size / emHeight; float descentF = descent * animChar.Font.Size / emHeight; //计算绘制文字的开始位置 float height = ascentF + descentF; float locY = (AnimationConfig.Height - height) / 2; switch (direction) { case SlieInDirection.RIGHT: animChar.SetLocation(AnimationConfig.Width, locY); animChar.CalcPath(); //计算字体的路径 animChar.Animation = AnimationUtil.CreatePostionAnimation(AnimationConfig.Width, finalPosX, locY, locY); break; case SlieInDirection.LEFT: int width = Convert.ToInt32(animChar.Size.Width); animChar.SetLocation(-width, locY); animChar.CalcPath(); animChar.Animation = AnimationUtil.CreatePostionAnimation(-width, finalPosX, locY, locY); break; case SlieInDirection.BOTTOM: animChar.SetLocation(finalPosX, AnimationConfig.Height); animChar.CalcPath(); animChar.Animation = AnimationUtil.CreatePostionAnimation(finalPosX, finalPosX, AnimationConfig.Height, locY); break; case SlieInDirection.TOP: animChar.SetLocation(finalPosX, -height); animChar.CalcPath(); animChar.Animation = AnimationUtil.CreatePostionAnimation(finalPosX, finalPosX, -height, locY); break; case SlieInDirection.VERBATIM: animChar.SetLocation(finalPosX, AnimationConfig.Height); animChar.CalcPath(); animChar.Animation = AnimationUtil.CreateTranslateAnimation(finalPosX, finalPosX, AnimationConfig.Height, locY); break; default: //SlieInDirection.RIGHT animChar.SetLocation(AnimationConfig.Width, locY); animChar.CalcPath(); //计算字体的路径 animChar.Animation = AnimationUtil.CreatePostionAnimation(AnimationConfig.Width, finalPosX, locY, locY); break; } }
/// <summary> /// 文字由向左进入动画 /// </summary> /// <param name="animChar"></param> public static void CreateRightInAnimation(AnimationChar animChar, float toX) { //计算与字体相关的参数 int ascent = animChar.Font.FontFamily.GetCellAscent(animChar.Font.Style); int descent = animChar.Font.FontFamily.GetCellDescent(animChar.Font.Style); int emHeight = animChar.Font.FontFamily.GetEmHeight(animChar.Font.Style); float ascentF = ascent * animChar.Font.Size / emHeight; float descentF = descent * animChar.Font.Size / emHeight; //计算绘制文字的开始位置 float locY = (AnimationConfig.Height - (ascentF + descentF)) / 2; animChar.SetLocation(AnimationConfig.Width, locY); animChar.CalcPath();//计算字体的路径 animChar.Animation = CreatePostionAnimation(AnimationConfig.Width, toX, locY, locY); }