Source: lib/text/cue.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. goog.provide('shaka.text.Cue');
  18. /**
  19. * Creates a Cue object.
  20. *
  21. * @param {number} startTime
  22. * @param {number} endTime
  23. * @param {!string} payload
  24. *
  25. * @constructor
  26. * @struct
  27. * @export
  28. */
  29. shaka.text.Cue = function(startTime, endTime, payload) {
  30. var Cue = shaka.text.Cue;
  31. /**
  32. * The start time of the cue in seconds and fractions of a second.
  33. * @type {number}
  34. */
  35. this.startTime = startTime;
  36. /**
  37. * The end time of the cue in seconds and fractions of a second.
  38. * @type {number}
  39. */
  40. this.endTime = endTime;
  41. /**
  42. * The text payload of the cue.
  43. * @type {!string}
  44. */
  45. this.payload = payload;
  46. /**
  47. * The indent (in percent) of the cue box in the direction defined by the
  48. * writing direction.
  49. * @type {?number}
  50. */
  51. this.position = null;
  52. /**
  53. * Position alignment of the cue.
  54. * @type {shaka.text.Cue.positionAlign}
  55. */
  56. this.positionAlign = Cue.positionAlign.AUTO;
  57. /**
  58. * Size of the cue box (in percents).
  59. * @type {number}
  60. */
  61. this.size = 100;
  62. /**
  63. * Alignment of the text inside the cue box.
  64. * @type {shaka.text.Cue.textAlign}
  65. */
  66. this.textAlign = Cue.textAlign.CENTER;
  67. /**
  68. * Text writing direction of the cue.
  69. * @type {shaka.text.Cue.writingDirection}
  70. */
  71. this.writingDirection = Cue.writingDirection.HORIZONTAL_LEFT_TO_RIGHT;
  72. /**
  73. * The way to interpret line field. (Either as an integer line number or
  74. * percentage from the display box).
  75. * @type {shaka.text.Cue.lineInterpretation}
  76. */
  77. this.lineInterpretation = Cue.lineInterpretation.LINE_NUMBER;
  78. /**
  79. * The offset from the display box in either number of lines or
  80. * percentage depending on the value of lineInterpretation.
  81. * @type {?number}
  82. */
  83. this.line = null;
  84. /**
  85. * Separation between line areas inside the cue box in px or em
  86. * (e.g. '100px'/'100em'). If not specified, should be no less than
  87. * the largest font size applied to the text in the cue.
  88. * @type {string}.
  89. */
  90. this.lineHeight = '';
  91. /**
  92. * Line alignment of the cue box.
  93. * @type {shaka.text.Cue.lineAlign}
  94. */
  95. this.lineAlign = Cue.lineAlign.CENTER;
  96. /**
  97. * Vertical alignments of the cues within their extents.
  98. * @type {shaka.text.Cue.displayAlign}
  99. */
  100. this.displayAlign = Cue.displayAlign.BEFORE;
  101. /**
  102. * Text color represented by any string that would be
  103. * accepted in CSS.
  104. * E. g. '#FFFFFF' or 'white'.
  105. * @type {!string}
  106. */
  107. this.color = '';
  108. /**
  109. * Text background color represented by any string that would be
  110. * accepted in CSS.
  111. * E. g. '#FFFFFF' or 'white'.
  112. * @type {!string}
  113. */
  114. this.backgroundColor = '';
  115. /**
  116. * Text font size in px or em (e.g. '100px'/'100em').
  117. * @type {string}
  118. */
  119. this.fontSize = '';
  120. /**
  121. * Text font weight. Either normal or bold.
  122. * @type {shaka.text.Cue.fontWeight}
  123. */
  124. this.fontWeight = Cue.fontWeight.NORMAL;
  125. /**
  126. * Text font style. Normal, italic or oblique.
  127. * @type {shaka.text.Cue.fontStyle}
  128. */
  129. this.fontStyle = Cue.fontStyle.NORMAL;
  130. /**
  131. * Text font family.
  132. * @type {!string}
  133. */
  134. this.fontFamily = '';
  135. /**
  136. * Text decoration. A combination of underline, overline
  137. * and line through. Empty array means no decoration.
  138. * @type {!Array.<!shaka.text.Cue.textDecoration>}
  139. */
  140. this.textDecoration = [];
  141. /**
  142. * Whether or not line wrapping should be applied
  143. * to the cue.
  144. * @type {boolean}
  145. */
  146. this.wrapLine = true;
  147. /**
  148. * Id of the cue.
  149. * @type {!string}
  150. */
  151. this.id = '';
  152. };
  153. /**
  154. * @enum {string}
  155. * @export
  156. */
  157. shaka.text.Cue.positionAlign = {
  158. LEFT: 'line-left',
  159. RIGHT: 'line-right',
  160. CENTER: 'center',
  161. AUTO: 'auto'
  162. };
  163. /**
  164. * @enum {string}
  165. * @export
  166. */
  167. shaka.text.Cue.textAlign = {
  168. LEFT: 'left',
  169. RIGHT: 'right',
  170. CENTER: 'center',
  171. START: 'start',
  172. END: 'end'
  173. };
  174. /**
  175. * @enum {string}
  176. * @export
  177. */
  178. shaka.text.Cue.displayAlign = {
  179. BEFORE: 'before',
  180. CENTER: 'center',
  181. AFTER: 'after'
  182. };
  183. /**
  184. * @enum {number}
  185. * @export
  186. */
  187. shaka.text.Cue.writingDirection = {
  188. HORIZONTAL_LEFT_TO_RIGHT: 0,
  189. HORIZONTAL_RIGHT_TO_LEFT: 1,
  190. VERTICAL_LEFT_TO_RIGHT: 2,
  191. VERTICAL_RIGHT_TO_LEFT: 3
  192. };
  193. /**
  194. * @enum {number}
  195. * @export
  196. */
  197. shaka.text.Cue.lineInterpretation = {
  198. LINE_NUMBER: 0,
  199. PERCENTAGE: 1
  200. };
  201. /**
  202. * @enum {string}
  203. * @export
  204. */
  205. shaka.text.Cue.lineAlign = {
  206. CENTER: 'center',
  207. START: 'start',
  208. END: 'end'
  209. };
  210. /**
  211. * In CSS font weight can be a number, where 400 is normal
  212. * and 700 is bold. Use these values for the enum for consistency.
  213. * @enum {number}
  214. * @export
  215. */
  216. shaka.text.Cue.fontWeight = {
  217. NORMAL: 400,
  218. BOLD: 700
  219. };
  220. /**
  221. * @enum {string}
  222. * @export
  223. */
  224. shaka.text.Cue.fontStyle = {
  225. NORMAL: 'normal',
  226. ITALIC: 'italic',
  227. OBLIQUE: 'oblique'
  228. };
  229. /**
  230. * @enum {string}
  231. * @export
  232. */
  233. shaka.text.Cue.textDecoration = {
  234. UNDERLINE: 'underline',
  235. LINE_THROUGH: 'lineThrough',
  236. OVERLINE: 'overline'
  237. };