[Libreoffice-bugs] [Bug 144576] Copy a table from Writer to plain text editor or as unformatted text pastes a list instead of matrix (like Calc does)

2023-10-30 Thread bugzilla-daemon
https://bugs.documentfoundation.org/show_bug.cgi?id=144576

Hossein  changed:

   What|Removed |Added

   Keywords|needsDevEval|difficultyMedium, easyHack,
   ||skillCpp

--- Comment #8 from Hossein  ---
(In reply to Stéphane Guillou (stragu) from comment #7)
> Hossein, could this qualify as an easy hack? Merged cells should be tested
> too.
Yes, I think this can be an EasyHack with the difficultyMedium.

Code pointers:

There are many steps in copy/pasting, including the data/format conversion and
clipboard format handling. Here, you have to know that the document is
converted to plain text via "text" filter.

The plaintext (ascii) filter is located here in the LibreOffice core source
code:

sw/source/filter/ascii

Therefore, to change the copy/paste output, you have to fix the ascii filter.
That would also provide the benefit that plain text export will be also fixed
as requested here.

In this folder, there are a few files:

$ ls sw/source/filter/ascii/
ascatr.cxx  parasc.cxx  wrtasc.cxx  wrtasc.hxx

To change the output, you have to edit this file:

sw/source/filter/ascii/wrtasc.cxx

In this file, there is a loop dedicated to create the output.

 // Output all areas of the pam into the ASC file
 do {
 bool bTstFly = true;
...
 }

Inside this loop, the code iterates over the nodes inside the document
structure, and extracts text from them. To check for yourself, add the one line
below to the code, build LO, and then test. You will see that a * is appended
before each node.

 SwTextNode* pNd = m_pCurrentPam->GetPoint()->GetNode().GetTextNode();
 if( pNd )
 {
+   Strm().WriteUChar('*');
  ...
 }

For example, having this table, with 1 blank paragraph up and down:

A | B
--|--
C | D

You will get this after copy/paste into a plain text editor:

*
*a
*b
*c
*d
*

To fix the bug, you have to differentiate between table cells and other nodes.
Then, you should take care of the table columns and print tab between them.

To go further, you can only add star before table cells:

 if( pNd )
 {
 SwTableNode *pTableNd = pNd->FindTableNode();
 if (pTableNd)
 {
 Strm().WriteUChar('*');
 }
 ...
 }

You can look into how other filters handled tables. For example, inside
sw/source/filter/html/htmltab.cxx you will see how table is managed, first cell
is tracked and appropriate functions to handle HTML table are called.

For the merged cells, I suggest the EasyHacker first checks the behavior in
other software, then design and implement the appropriate behavior.

To gain a better understanding of the Writer document model / layout, please
see this document:

Writer/Core And Layout
https://wiki.openoffice.org/wiki/Writer/Core_And_Layout

And also this presentation:

Introduction to Writer Development - LibreOffice 2023 Conference Workshop
Miklos Vajna
https://www.youtube.com/watch?v=oM0tB1A0JHA

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Libreoffice-bugs] [Bug 144576] Copy a table from Writer to plain text editor or as unformatted text pastes a list instead of matrix (like Calc does)

2023-10-20 Thread bugzilla-daemon
https://bugs.documentfoundation.org/show_bug.cgi?id=144576

Stéphane Guillou (stragu)  changed:

   What|Removed |Added

 Blocks||103407, 108844
   Keywords||needsDevEval
Summary|Copy a table from Writer to |Copy a table from Writer to
   |Notepad pastes a list   |plain text editor or as
   |instead of matrix   |unformatted text pastes a
   ||list instead of matrix
   ||(like Calc does)
 CC||hoss...@libreoffice.org,
   ||stephane.guillou@libreoffic
   ||e.org

--- Comment #7 from Stéphane Guillou (stragu) 
 ---
Copying my comment from duplicate bug 157605:

Same in OOo 3.3, so inherited.
Reproduced in recent trunk build:

Version: 24.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: b83f069101f1e6d8aaac09a805f02bbc4c619e7a
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: threaded

Table copied from OnlyOffice gives the OP's expected results:

1   Line 1
2   Line 2

(and uses tabs to separate columns, as it should)

This is the same as copy-pasting from Calc:

1   Line 1
2   Line 2

So, to me, it's sensible to make Writer tables behave the same as Calc when
copy-pasted.

Hossein, could this qualify as an easy hack? Merged cells should be tested too.


Referenced Bugs:

https://bugs.documentfoundation.org/show_bug.cgi?id=103407
[Bug 103407] [META] Unify behaviour and functions across apps
https://bugs.documentfoundation.org/show_bug.cgi?id=108844
[Bug 108844] [META] Cut/copy bugs and enhancements
-- 
You are receiving this mail because:
You are the assignee for the bug.