Skip to content

Commit 8f06d37

Browse files
committed
Merge branch 'topic/vadim/odf' into 'edge'
ODF improvements See merge request eng/ide/gnatdoc!161
2 parents 0645784 + c2b39d8 commit 8f06d37

9 files changed

+266
-37
lines changed

share/gnatdoc/odf/template/documentation.fodt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
</style:style>
221221

222222
<style:style style:name="GNATdoc_20_code_20_block" style:display-name="GNATdoc code block" style:family="paragraph" style:parent-style-name="Standard">
223+
<style:paragraph-properties fo:margin-top="0in" fo:margin-bottom="0.0972in" style:contextual-spacing="false" fo:line-height="115%"/>
223224
<style:text-properties style:font-name="Liberation Mono" fo:font-family="&apos;Liberation Mono&apos;" style:font-family-generic="modern" style:font-pitch="fixed" fo:font-size="10pt" style:font-name-asian="Noto Sans Mono CJK SC" style:font-family-asian="&apos;Noto Sans Mono CJK SC&apos;" style:font-family-generic-asian="modern" style:font-pitch-asian="fixed" style:font-size-asian="10pt" style:font-name-complex="Liberation Mono" style:font-family-complex="&apos;Liberation Mono&apos;" style:font-family-generic-complex="modern" style:font-pitch-complex="fixed" style:font-size-complex="10pt"/>
224225
</style:style>
225226
<style:style style:name="GNATdoc_20_paragraph" style:display-name="GNATdoc paragraph" style:family="paragraph" style:parent-style-name="Standard" style:class="text">
@@ -356,30 +357,35 @@
356357
<text:h tal:condition='entity/simple_types' text:style-name="Heading_20_3" text:outline-level="3">Simple Types</text:h>
357358
<text:section tal:omit-tag='' tal:repeat='item entity/simple_types'>
358359
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
360+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
359361
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
360362
</text:section>
361363

362364
<text:h tal:condition='entity/array_types' text:style-name="Heading_20_3" text:outline-level="3">Array Types</text:h>
363365
<text:section tal:omit-tag='' tal:repeat='item entity/array_types'>
364366
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
367+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
365368
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
366369
</text:section>
367370

368371
<text:h tal:condition='entity/record_types' text:style-name="Heading_20_3" text:outline-level="3">Record Types</text:h>
369372
<text:section tal:omit-tag='' tal:repeat='item entity/record_types'>
370373
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
374+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
371375
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
372376
</text:section>
373377

374378
<text:h tal:condition='entity/interface_types' text:style-name="Heading_20_3" text:outline-level="3">Interface Types</text:h>
375379
<text:section tal:omit-tag='' tal:repeat='item entity/interface_types'>
376380
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
381+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
377382
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
378383
</text:section>
379384

380385
<text:h tal:condition='entity/tagged_types' text:style-name="Heading_20_3" text:outline-level="3">Tagged Types</text:h>
381386
<text:section tal:omit-tag='' tal:repeat='item entity/tagged_types'>
382387
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
388+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
383389
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
384390
</text:section>
385391

@@ -398,36 +404,42 @@
398404
<text:h tal:condition='entity/access_types' text:style-name="Heading_20_3" text:outline-level="3">Access Types</text:h>
399405
<text:section tal:omit-tag='' tal:repeat='item entity/access_types'>
400406
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
407+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
401408
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
402409
</text:section>
403410

404411
<text:h tal:condition='entity/subtypes' text:style-name="Heading_20_3" text:outline-level="3">Subtypes</text:h>
405412
<text:section tal:omit-tag='' tal:repeat='item entity/subtypes'>
406413
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
414+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
407415
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
408416
</text:section>
409417

410418
<text:h tal:condition='entity/constants' text:style-name="Heading_20_3" text:outline-level="3">Constants</text:h>
411419
<text:section tal:omit-tag='' tal:repeat='item entity/constants'>
412420
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
421+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
413422
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
414423
</text:section>
415424

416425
<text:h tal:condition='entity/variables' text:style-name="Heading_20_3" text:outline-level="3">Variables</text:h>
417426
<text:section tal:omit-tag='' tal:repeat='item entity/variables'>
418427
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
428+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
419429
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
420430
</text:section>
421431

422432
<text:h tal:condition='entity/entries' text:style-name="Heading_20_3" text:outline-level="3">Entries</text:h>
423433
<text:section tal:omit-tag='' tal:repeat='item entity/entries'>
424434
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
435+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
425436
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
426437
</text:section>
427438

428439
<text:h tal:condition='entity/subprograms' text:style-name="Heading_20_3" text:outline-level="3">Subprograms</text:h>
429440
<text:section tal:omit-tag='' tal:repeat='item entity/subprograms'>
430441
<text:h tal:content='item/name' text:style-name="Heading_20_4" text:outline-level="4">Heading 4</text:h>
442+
<text:p tal:omit-tag='' tal:content='item/code_odf'>Entity declaration</text:p>
431443
<text:p tal:omit-tag='' tal:content='item/documentation/description_odf'>Entity description</text:p>
432444
<text:section tal:omit-tag='' tal:condition='item/documentation/parameters'>
433445
<text:list text:style-name="GNATdoc_20_component_20_list">
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
------------------------------------------------------------------------------
2+
-- GNAT Documentation Generation Tool --
3+
-- --
4+
-- Copyright (C) 2025, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
18+
with Ada.Unchecked_Deallocation;
19+
with GNAT.Strings;
20+
21+
with VSS.Strings.Conversions;
22+
with VSS.Strings.Converters.Decoders;
23+
24+
with GNATCOLL.Coders.Base64;
25+
26+
package body GNATdoc.Backend.ODF_Markup.Image_Utilities is
27+
28+
type Stream_Element_Array_Access is
29+
access all Ada.Streams.Stream_Element_Array;
30+
31+
procedure Free is
32+
new Ada.Unchecked_Deallocation
33+
(Ada.Streams.Stream_Element_Array, Stream_Element_Array_Access);
34+
35+
-----------------
36+
-- Load_Encode --
37+
-----------------
38+
39+
procedure Load_Encode
40+
(Destination : VSS.Strings.Virtual_String;
41+
Encoded_Content : out VSS.Strings.Virtual_String)
42+
is
43+
use type Ada.Streams.Stream_Element_Offset;
44+
45+
File : GNATCOLL.VFS.Virtual_File;
46+
Binary : GNAT.Strings.String_Access;
47+
Encoded : Stream_Element_Array_Access;
48+
Coder : GNATCOLL.Coders.Base64.Encoder_Type;
49+
50+
begin
51+
File :=
52+
GNATCOLL.VFS.Create_From_UTF8
53+
(VSS.Strings.Conversions.To_UTF_8_String (Destination));
54+
55+
if not File.Is_Regular_File then
56+
raise Program_Error;
57+
end if;
58+
59+
Binary := File.Read_File;
60+
Encoded := new Ada.Streams.Stream_Element_Array (1 .. Binary'Length * 2);
61+
62+
declare
63+
Binary_Data : Ada.Streams.Stream_Element_Array (1 .. Binary'Length)
64+
with Import, Address => Binary.all'Address;
65+
In_Last : Ada.Streams.Stream_Element_Count;
66+
Out_Last : Ada.Streams.Stream_Element_Count;
67+
Decoder : VSS.Strings.Converters.Decoders.Virtual_String_Decoder;
68+
69+
begin
70+
Coder.Initialize;
71+
Coder.Transcode
72+
(In_Data => Binary_Data,
73+
In_Last => In_Last,
74+
Out_Data => Encoded.all,
75+
Out_Last => Out_Last,
76+
Flush => GNATCOLL.Coders.Finish);
77+
78+
Decoder.Initialize
79+
("ISO-8859-1",
80+
[VSS.Strings.Converters.Stateless => True, others => False]);
81+
Encoded_Content :=
82+
Decoder.Decode (Encoded (Encoded'First .. Out_Last));
83+
end;
84+
85+
Free (Encoded);
86+
GNAT.Strings.Free (Binary);
87+
end Load_Encode;
88+
89+
end GNATdoc.Backend.ODF_Markup.Image_Utilities;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
------------------------------------------------------------------------------
2+
-- GNAT Documentation Generation Tool --
3+
-- --
4+
-- Copyright (C) 2025, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
18+
package GNATdoc.Backend.ODF_Markup.Image_Utilities is
19+
20+
procedure Load_Encode
21+
(Destination : VSS.Strings.Virtual_String;
22+
Encoded_Content : out VSS.Strings.Virtual_String);
23+
-- Loads given file, converts its content into Base64 encoded form and
24+
-- transforms to `Virtual_String`.
25+
26+
end GNATdoc.Backend.ODF_Markup.Image_Utilities;

source/backend/odf/gnatdoc-backend-odf_markup.adb

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,24 @@ with Markdown.Blocks.Paragraphs;
2626
with Markdown.Documents;
2727
with Markdown.Parsers.GNATdoc_Enable;
2828

29+
with GNATdoc.Backend.ODF_Markup.Image_Utilities;
30+
2931
package body GNATdoc.Backend.ODF_Markup is
3032

31-
Draw_Namespace : constant VSS.IRIs.IRI :=
33+
Draw_Namespace : constant VSS.IRIs.IRI :=
3234
VSS.IRIs.To_IRI ("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0");
33-
Text_Namespace : constant VSS.IRIs.IRI :=
35+
Office_Namespace : constant VSS.IRIs.IRI :=
36+
VSS.IRIs.To_IRI ("urn:oasis:names:tc:opendocument:xmlns:office:1.0");
37+
Text_Namespace : constant VSS.IRIs.IRI :=
3438
VSS.IRIs.To_IRI ("urn:oasis:names:tc:opendocument:xmlns:text:1.0");
3539

36-
Line_Break_Element : constant VSS.Strings.Virtual_String := "line-break";
37-
List_Element : constant VSS.Strings.Virtual_String := "list";
38-
List_Item_Element : constant VSS.Strings.Virtual_String := "list-item";
39-
P_Element : constant VSS.Strings.Virtual_String := "p";
40+
Binary_Data_Element : constant VSS.Strings.Virtual_String := "binary-data";
41+
Frame_Element : constant VSS.Strings.Virtual_String := "frame";
42+
Image_Element : constant VSS.Strings.Virtual_String := "image";
43+
Line_Break_Element : constant VSS.Strings.Virtual_String := "line-break";
44+
List_Element : constant VSS.Strings.Virtual_String := "list";
45+
List_Item_Element : constant VSS.Strings.Virtual_String := "list-item";
46+
P_Element : constant VSS.Strings.Virtual_String := "p";
4047

4148
Style_Name_Attribute : constant VSS.Strings.Virtual_String :=
4249
"style-name";
@@ -185,6 +192,36 @@ package body GNATdoc.Backend.ODF_Markup is
185192
end loop;
186193
end Build_Block_Container;
187194

195+
-------------------------------
196+
-- Build_Code_Snipped_Markup --
197+
-------------------------------
198+
199+
function Build_Code_Snipped_Markup
200+
(Text : VSS.String_Vectors.Virtual_String_Vector)
201+
return VSS.XML.Event_Vectors.Vector is
202+
begin
203+
return Result : VSS.XML.Event_Vectors.Vector do
204+
Write_Start_Element (Result, Text_Namespace, P_Element);
205+
Write_Attribute
206+
(Result,
207+
Text_Namespace,
208+
Style_Name_Attribute,
209+
GNATdoc_Code_Block_Style);
210+
211+
for Index in Text.First_Index .. Text.Last_Index loop
212+
if Index /= Text.First_Index then
213+
Write_Start_Element
214+
(Result, Text_Namespace, Line_Break_Element);
215+
Write_End_Element (Result, Text_Namespace, Line_Break_Element);
216+
end if;
217+
218+
Write_Text (Result, Text.Element (Index));
219+
end loop;
220+
221+
Write_End_Element (Result, Text_Namespace, P_Element);
222+
end return;
223+
end Build_Code_Snipped_Markup;
224+
188225
-------------------------------
189226
-- Build_Indented_Code_Block --
190227
-------------------------------
@@ -338,12 +375,20 @@ package body GNATdoc.Backend.ODF_Markup is
338375
overriding procedure Enter_Image
339376
(Self : in out Annotated_Text_Builder;
340377
Destination : VSS.Strings.Virtual_String;
341-
Title : VSS.Strings.Virtual_String) is
378+
Title : VSS.Strings.Virtual_String)
379+
is
380+
Encoded_Content : VSS.Strings.Virtual_String;
381+
342382
begin
343383
Self.Image := True;
344384

345-
Write_Start_Element (Self.Stream, Draw_Namespace, "frame");
346-
Write_Start_Element (Self.Stream, Draw_Namespace, "image");
385+
GNATdoc.Backend.ODF_Markup.Image_Utilities.Load_Encode
386+
(Destination, Encoded_Content);
387+
388+
Write_Start_Element (Self.Stream, Draw_Namespace, Frame_Element);
389+
Write_Start_Element (Self.Stream, Draw_Namespace, Image_Element);
390+
Write_Start_Element (Self.Stream, Office_Namespace, Binary_Data_Element);
391+
Write_Text (Self.Stream, Encoded_Content);
347392
end Enter_Image;
348393

349394
------------------
@@ -405,8 +450,9 @@ package body GNATdoc.Backend.ODF_Markup is
405450
Destination : VSS.Strings.Virtual_String;
406451
Title : VSS.Strings.Virtual_String) is
407452
begin
408-
Write_End_Element (Self.Stream, Draw_Namespace, "image");
409-
Write_End_Element (Self.Stream, Draw_Namespace, "frame");
453+
Write_End_Element (Self.Stream, Office_Namespace, Binary_Data_Element);
454+
Write_End_Element (Self.Stream, Draw_Namespace, Image_Element);
455+
Write_End_Element (Self.Stream, Draw_Namespace, Frame_Element);
410456

411457
Self.Image := False;
412458
Self.Text.Clear;

source/backend/odf/gnatdoc-backend-odf_markup.ads

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ package GNATdoc.Backend.ODF_Markup is
2424
(Text : VSS.String_Vectors.Virtual_String_Vector)
2525
return VSS.XML.Event_Vectors.Vector;
2626

27+
function Build_Code_Snipped_Markup
28+
(Text : VSS.String_Vectors.Virtual_String_Vector)
29+
return VSS.XML.Event_Vectors.Vector;
30+
2731
end GNATdoc.Backend.ODF_Markup;

source/backend/xml_templates/gnatdoc-comments-proxies.adb

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18-
with VSS.XML.Event_Vectors;
1918
with VSS.XML.Templates.Proxies.Strings;
20-
with VSS.XML.Templates.Values;
2119

2220
with GNATdoc.Backend.HTML_Markup;
2321
with GNATdoc.Backend.ODF_Markup;
22+
with GNATdoc.Proxies;
2423

2524
package body GNATdoc.Comments.Proxies is
2625

@@ -67,15 +66,6 @@ package body GNATdoc.Comments.Proxies is
6766
Name : VSS.Strings.Virtual_String)
6867
return VSS.XML.Templates.Proxies.Abstract_Proxy'Class;
6968

70-
type Markup_Proxy is
71-
limited new VSS.XML.Templates.Proxies.Abstract_Value_Proxy with
72-
record
73-
Markup : VSS.XML.Event_Vectors.Vector;
74-
end record;
75-
76-
overriding function Value
77-
(Self : Markup_Proxy) return VSS.XML.Templates.Values.Value;
78-
7969
---------------
8070
-- Component --
8171
---------------
@@ -123,7 +113,7 @@ package body GNATdoc.Comments.Proxies is
123113
end loop;
124114

125115
return
126-
Markup_Proxy'
116+
GNATdoc.Proxies.Markup_Proxy'
127117
(Markup => GNATdoc.Backend.HTML_Markup.Build_Markup (Text));
128118
end;
129119

@@ -139,7 +129,7 @@ package body GNATdoc.Comments.Proxies is
139129
end loop;
140130

141131
return
142-
Markup_Proxy'
132+
GNATdoc.Proxies.Markup_Proxy'
143133
(Markup => GNATdoc.Backend.ODF_Markup.Build_Markup (Text));
144134
end;
145135

@@ -188,13 +178,13 @@ package body GNATdoc.Comments.Proxies is
188178

189179
elsif Name = "description" then
190180
return
191-
Markup_Proxy'
181+
GNATdoc.Proxies.Markup_Proxy'
192182
(Markup =>
193183
GNATdoc.Backend.HTML_Markup.Build_Markup (Self.Section.Text));
194184

195185
elsif Name = "description_odf" then
196186
return
197-
Markup_Proxy'
187+
GNATdoc.Proxies.Markup_Proxy'
198188
(Markup =>
199189
GNATdoc.Backend.ODF_Markup.Build_Markup (Self.Section.Text));
200190

@@ -269,14 +259,4 @@ package body GNATdoc.Comments.Proxies is
269259
return Section_Vectors.Has_Element (Self.Position);
270260
end Next;
271261

272-
-----------
273-
-- Value --
274-
-----------
275-
276-
overriding function Value
277-
(Self : Markup_Proxy) return VSS.XML.Templates.Values.Value is
278-
begin
279-
return (VSS.XML.Templates.Values.Content, Self.Markup);
280-
end Value;
281-
282262
end GNATdoc.Comments.Proxies;

0 commit comments

Comments
 (0)