| 1 |
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- |
| 2 |
# |
| 3 |
# This file is part of the LibreOffice project. |
| 4 |
# |
| 5 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
# |
| 9 |
|
| 10 |
from uitest.framework import UITestCase |
| 11 |
from com.sun.star.awt import Point |
| 12 |
import pathlib |
| 13 |
import tempfile |
| 14 |
|
| 15 |
class tdf170386(UITestCase): |
| 16 |
def test_tdf170386(self): |
| 17 |
# Create a Draw document, lock its controllers, add a text shape, and apply bold to it. |
| 18 |
# Unlock the controllers, save and reload. The expectation is, that the applied bold |
| 19 |
# remains applied to the text. |
| 20 |
# There are two levels where bold is applied to the shape and its text: |
| 21 |
# 1. The shape itself (draw:frame element) has a paragraph autostyle applied through |
| 22 |
# draw:text-style-name attribute, and that defined the font weight; |
| 23 |
# 2. The paragraphs of text (text:p elements) may apply their own paragraph autoformats. |
| 24 |
# It is a question, why the draw:frame's draw:text-style-name apparently is not applied |
| 25 |
# to the paragraphs inside the shape, when the paragraphs don't define their own style; |
| 26 |
# but the bug was, that the paragraphs missed their autostyles, and so the text runs were |
| 27 |
# not bold (even though the shape-level property was present). It happened because the |
| 28 |
# object used to collect text properties on save wasn't notified on the changes that |
| 29 |
# happened when the model was locked. |
| 30 |
|
| 31 |
with tempfile.NamedTemporaryFile(suffix=".odg") as temp: |
| 32 |
url = pathlib.Path(temp.name).as_uri() |
| 33 |
|
| 34 |
with self.ui_test.create_doc_in_start_center("draw") as xModel: |
| 35 |
xPage = xModel.getDrawPages().getByIndex(0) |
| 36 |
xModel.lockControllers() |
| 37 |
xShape = xModel.createInstance("com.sun.star.drawing.TextShape") |
| 38 |
xPage.add(xShape) |
| 39 |
xShape.setString("Some Text") |
| 40 |
xShape.setPosition(Point(2000, 600)) |
| 41 |
xShape.setPropertyValue("CharWeight", 150.0) |
| 42 |
xModel.unlockControllers() |
| 43 |
xModel.storeAsURL(url, []) |
| 44 |
|
| 45 |
with self.ui_test.load_file(url) as xModel: |
| 46 |
xShape = xModel.getDrawPages().getByIndex(0).getByIndex(0) |
| 47 |
# The shape-level property was OK even without the fix: |
| 48 |
self.assertEqual(150.0, xShape.getPropertyValue("CharWeight")) |
| 49 |
# Test that the text inside the shape (accessed using cursor) has correct weight. |
| 50 |
# Without the fix, this failed with "150.0 != 100.0" |
| 51 |
self.assertEqual(150.0, xShape.createTextCursor().getPropertyValue("CharWeight")) |
| 52 |
|
| 53 |
# vim: set shiftwidth=4 softtabstop=4 expandtab: |