import pytest from tests.base.interactive import InteractiveTestCase import pyglet from pyglet.text import caret, layout doctext = """ (metadata including title is not displayed.) Test document

HTML test document

Several paragraphs of HTML formatted text follow. Ensure they are formatted as they are described. Here is a copyright symbol: © and again, using hexadecimal ref: ©.

This paragraph has some bold and italic and bold italic text.

This paragraph has some emphasis and strong and emphatic strong text.

This paragraph demonstrates superscript: a2 + b2 = c2; and subscript: H2O.

This paragraph uses the <font> element: Courier New, size 1, size 2, size 3, size 4, size 5, size 6, size 7.

This paragraph uses relative sizes: size 5size 3

Font color changes to red, green and pastel blue using a hexadecimal number.

This text is underlined. This text is underlined and green.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Centered paragraph.

Right-aligned paragraph.

<div> element instead of paragraph.
This sentence should start a new paragraph, as the div is nested.
This sentence should start a new paragraph, as the nested div was closed.
This text is preformatted.
Hard line breaks
   Indentation.  Inline formatting is still ok.

This paragraph
has a
line break
after every
two words.

This paragraph is blockquote. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Nested blockquote. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Here is a quotation. The previous paragraph mentioned, Lorem ipsum dolor sit amet, ....
  1. Numbered list.
  2. Item 2.
  3. Item 3.
  4. Item 10
  5. Item 11
  1. Numbered list starting at 12.
  2. Item 13.
  1. Numbered list with "a" type
  2. Item 2
  3. Item 3
  1. Numbered list with "A" type
  2. Item 2
  3. Item 3
  1. Numbered list with "i" type
  2. Item 2
  3. Item 3
  1. Numbered list with "I" type
  2. Item 2
  3. Item 3
Here's a definition list:
Term
Definition.
Term
Definition.
Term
Definition.
""" class TestWindow(pyglet.window.Window): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.batch = pyglet.graphics.Batch() self.document = pyglet.text.decode_html(doctext) self.margin = 2 self.layout = layout.IncrementalTextLayout(self.document, width=self.width - self.margin * 2, height=self.height - self.margin * 2, multiline=True, batch=self.batch) self.caret = caret.Caret(self.layout) self.push_handlers(self.caret) self.set_mouse_cursor(self.get_system_mouse_cursor('text')) def on_resize(self, width, height): super().on_resize(width, height) self.layout.begin_update() self.layout.x = self.margin self.layout.y = self.margin self.layout.width = width - self.margin * 2 self.layout.height = height - self.margin * 2 self.layout.end_update() def on_mouse_scroll(self, x, y, scroll_x, scroll_y): self.layout.view_x -= scroll_x self.layout.view_y += scroll_y * 16 def on_draw(self): pyglet.gl.glClearColor(1, 1, 1, 1) self.clear() self.batch.draw() def on_key_press(self, symbol, modifiers): super().on_key_press(symbol, modifiers) if symbol == pyglet.window.key.TAB: self.caret.on_text('\t') @pytest.mark.requires_user_action class HtmlTestCase(InteractiveTestCase): """Test that HTML data is decoded into a formatted document. Press ESC to exit the test. """ def test_html(self): self.window = TestWindow(resizable=True, visible=False) self.window.set_visible() pyglet.app.run() self.user_verify('Pass test?', take_screenshot=False)