请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册
查看: 185|回复: 1

萌新请教\pos与\an关联性的问题

该用户从未签到

1

主题

1

回帖

0

VC币

新手上路

Rank: 1

积分
20
insuaaaaa 发表于 2025-3-13 05:06:06 | 显示全部楼层 |阅读模式
本帖最后由 insuaaaaa 于 2025-3-13 05:07 编辑

对于已经通过\pos和\an固定好的字符,如何得到在另一种\an之下与其位置完全重合的\pos数值

比如先有了一个\an7的蛤,然后增加一个\an5的蛤,除了手工瞄准,可不可以通过算法计算\pos得出一个与其完全重合的\an5的蛤
回复

使用道具 举报

  • TA的每日心情
    慵懒
    半小时前
  • 签到天数: 1176 天

    [LV.10]以坛为家III

    28

    主题

    462

    回帖

    1万

    VC币

    星辰大海

    Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20

    积分
    1545039
    tmdtmdtmdqq 发表于 2025-3-13 09:48:07 | 显示全部楼层
    本帖最后由 tmdtmdtmdqq 于 2025-3-13 10:30 编辑

    以前写的,在我修的某个字幕中有用过来作特效。
    已经考虑过\an标签、\pos标签、margin_l、margin_r、margin_v设置的情况(\move标签不适用),非特殊情况下使用按理说没问题。
    注意设置好字幕文件中的PlayResX、PlayResY属性,否则要在函数调用中传入字幕空间的长、宽。

    用法:
    !line_screen_pos_xy_tag(7)!    则输出   \an7\pos(xxx1, yyy1)
    !line_screen_pos_xy_tag(3, 1920, 1080)!    则输出   \an3\pos(xxx2, yyy2)

    附加功能
    !line_screen_pos_xy(7)!    则输出两个值   xxx, yyy
    !line_screen_ltrb_pos()!   则输出四个值  left, top, right, bottom  (计算内联坐标\pos后的四个边的值,不带边界阴影)
    !line_screen_ltrb_pos_with_bord_shad()!   则输出四个值  left, top, right, bottom  (计算内联坐标\pos后的四个边的值,带边界阴影。这个函数没写在测试文件中,仅在下面列出)

    其它的例子就看测试文件(注释掉样式为fx且层为1的行,就能看到原始行,也就能检查是否重合)。

    1. function pos_map_vector(src_an, src_x, src_y, trg_an, trg_x, trg_y, width, height)
    2.   local src_left, src_top, trg_left, trg_top;

    3.   src_left = src_x - (src_an%3==1 and 0 or (src_an%3==2 and width/2 or width));
    4.   src_top = src_y - (src_an<=3 and height or (src_an<=6 and height/2 or 0));
    5.   
    6.   trg_left = trg_x - (trg_an%3==1 and 0 or (trg_an%3==2 and width/2 or width));
    7.   trg_top = trg_y - (trg_an<=3 and height or (trg_an<=6 and height/2 or 0));

    8.   return trg_left - src_left, trg_top - src_top;
    9. end

    10. function line_screen_ltrb_pos(screen_width, screen_height)
    11.   local vline = orgline;
    12.   screen_width = screen_width or meta.res_x;
    13.   screen_height = screen_height or meta.res_y;
    14.   local src_an = vline.styleref.align;
    15.   local trg_an = _G.tonumber(string.match(vline.text, "\\an%s*(%d)")) or src_an;
    16.   local trg_x, trg_y = string.match(vline.text, "\\pos%(%s*(%-?[%d.]+)%s*,%s*(-?[%d.]+)%s*%)");
    17.   if trg_x == nil or trg_y == nil then
    18.     if trg_an == src_an then
    19.       trg_x, trg_y = vline.x, vline.y;
    20.     else
    21.       trg_x = (trg_an%3==1 and vline.eff_margin_l or (trg_an%3==2 and (screen_width+vline.eff_margin_l-vline.eff_margin_r)/2 or screen_width-vline.eff_margin_r));
    22.       trg_y = (trg_an<=3 and screen_height-line.eff_margin_v or (trg_an<=6 and screen_height/2 or line.eff_margin_v));
    23.     end
    24.   else
    25.     trg_x, trg_y = _G.tonumber(trg_x), _G.tonumber(trg_y);
    26.   end
    27.   
    28.   local dx, dy = pos_map_vector(src_an, vline.x, vline.y, trg_an, trg_x, trg_y, vline.right-vline.left, vline.bottom-vline.top);
    29.   return vline.left + dx, vline.top + dy, vline.right + dx, vline.bottom + dy;
    30. end

    31. function line_screen_pos_xy(an, screen_width, screen_height)
    32.   local vline = orgline;
    33.   local left, top, right, bottom = line_screen_ltrb_pos(screen_width, screen_height);
    34.   an = an or _G.tonumber(string.match(vline.text, "\\an%s*(%d)")) or vline.styleref.align;
    35.   local x = (an%3==1 and left or (an%3==2 and (left+right)/2 or right));
    36.   local y = (an<=3 and bottom or (an<=6 and (top+bottom)/2 or top));
    37.   return x, y;
    38. end

    39. function line_screen_pos_xy_tag(an, screen_width, screen_height, precision)
    40.   precision = precision or 2;
    41.   local vline = orgline;
    42.   local an_str = an and "\\an"..an or _G.table.concat({string.match(vline.text, "(\\an)%s*(%d)")}, "");
    43.   local pfmt = string.format("%s\\pos(%%.%df,%%.%df)", an_str, precision, precision);
    44.   return pfmt:format(line_screen_pos_xy(an, screen_width, screen_height));
    45. end

    46. -- ;附送方法
    47. function line_screen_ltrb_pos_with_bord_shad(screen_width, screen_height)
    48.   local vline = orgline;
    49.   local left, top, right, bottom = line_screen_ltrb_pos(screen_width, screen_height);
    50.   local bord = _G.tonumber(string.match(vline.text, "\\bord%s*(%-?[%d.]+)")) or vline.styleref.outline;
    51.   local xshad = _G.tonumber(string.match(vline.text, "\\x?shad%s*(%-?[%d.]+)")) or vline.styleref.shadow;
    52.   local yshad = _G.tonumber(string.match(vline.text, "\\y?shad%s*(%-?[%d.]+)")) or vline.styleref.shadow;
    53.   left = left - bord - (xshad<0 and -xshad or 0);
    54.   top = top - bord - (yshad<0 and -yshad or 0);
    55.   right = right + bord + (xshad>0 and xshad or 0);
    56.   bottom = bottom + bord + (yshad>0 and yshad or 0);
    57.   return left, top, right, bottom;
    58. end

    复制代码


    ltrb_test.rar (1.69 KB, 下载次数: 4)


    欢迎报错继续向上改进我改进过的字幕。
    请勿将无实质性修改、劣化精简本人改进过的字幕重新发布到此论坛:如仅改名、仅打包、修改总错字数≤5、删除特效等。       ——20230204
    本人改进过的字幕,禁止以任何形式进行商用。若要附带在视频、种子中发布,请先咨询。      ——20231203
    一些字幕搜寻、制作的方法和经验汇总  →  >>>帖子<<<
    禁止DBD-Raws及其相关人士使用本人所有制作或修正改进过的字幕(包括过往的)      ——20240730
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    快速回复 返回顶部 返回列表