(f, c, width, height, styleid)
| 317 | |
| 318 | |
| 319 | def WriteCommentAcfunPositioned(f, c, width, height, styleid): |
| 320 | AcfunPlayerSize = (560, 400) |
| 321 | ZoomFactor = GetZoomFactor(AcfunPlayerSize, (width, height)) |
| 322 | |
| 323 | def GetPosition(InputPos, isHeight): |
| 324 | isHeight = int(isHeight) # True -> 1 |
| 325 | return AcfunPlayerSize[isHeight]*ZoomFactor[0]*InputPos*0.001+ZoomFactor[isHeight+1] |
| 326 | |
| 327 | def GetTransformStyles(x=None, y=None, scale_x=None, scale_y=None, rotate_z=None, rotate_y=None, color=None, alpha=None): |
| 328 | styles = [] |
| 329 | if x is not None and y is not None: |
| 330 | styles.append('\\pos(%s, %s)' % (x, y)) |
| 331 | if scale_x is not None: |
| 332 | styles.append('\\fscx%s' % scale_x) |
| 333 | if scale_y is not None: |
| 334 | styles.append('\\fscy%s' % scale_y) |
| 335 | if rotate_z is not None and rotate_y is not None: |
| 336 | assert x is not None |
| 337 | assert y is not None |
| 338 | styles.append('\\frx%s\\fry%s\\frz%s\\fax%s\\fay%s' % ConvertFlashRotation(rotate_y, rotate_z, (x-ZoomFactor[1])/(width-ZoomFactor[1]*2), (y-ZoomFactor[2])/(height-ZoomFactor[2]*2))) |
| 339 | if color is not None: |
| 340 | styles.append('\\c&H%02X%02X%02X&' % (color & 0xff, (color >> 8) & 0xff, (color >> 16) & 0xff)) |
| 341 | if color == 0x000000: |
| 342 | styles.append('\\3c&HFFFFFF&') |
| 343 | if alpha is not None: |
| 344 | alpha = 255-round(alpha*255) |
| 345 | styles.append('\\alpha&H%02X' % alpha) |
| 346 | return styles |
| 347 | |
| 348 | def FlushCommentLine(f, text, styles, start_time, end_time, styleid): |
| 349 | if end_time > start_time: |
| 350 | f.write('Dialogue: -1,%(start)s,%(end)s,%(styleid)s,,0,0,0,,{%(styles)s}%(text)s\n' % {'start': ConvertTimestamp(start_time), 'end': ConvertTimestamp(end_time), 'styles': ''.join(styles), 'text': text, 'styleid': styleid}) |
| 351 | |
| 352 | try: |
| 353 | comment_args = c[3] |
| 354 | text = ASSEscape(str(comment_args['n']).replace('\r', '\n').replace('\r', '\n')) |
| 355 | common_styles = [] |
| 356 | anchor = {0: 7, 1: 8, 2: 9, 3: 4, 4: 5, 5: 6, 6: 1, 7: 2, 8: 3}.get(comment_args.get('c', 0), 7) |
| 357 | if anchor != 7: |
| 358 | common_styles.append('\\an%s' % anchor) |
| 359 | font = comment_args.get('w') |
| 360 | if font: |
| 361 | font = dict(font) |
| 362 | fontface = font.get('f') |
| 363 | if fontface: |
| 364 | common_styles.append('\\fn%s' % ASSEscape(str(fontface))) |
| 365 | fontbold = bool(font.get('b')) |
| 366 | if fontbold: |
| 367 | common_styles.append('\\b1') |
| 368 | common_styles.append('\\fs%s' % round(c[6]*ZoomFactor[0])) |
| 369 | isborder = bool(comment_args.get('b', True)) |
| 370 | if not isborder: |
| 371 | common_styles.append('\\bord0') |
| 372 | to_pos = dict(comment_args.get('p', {'x': 0, 'y': 0})) |
| 373 | to_x = round(GetPosition(int(to_pos.get('x', 0)), False)) |
| 374 | to_y = round(GetPosition(int(to_pos.get('y', 0)), True)) |
| 375 | to_scale_x = round(float(comment_args.get('e', 1.0))*100) |
| 376 | to_scale_y = round(float(comment_args.get('f', 1.0))*100) |
no test coverage detected