summaryrefslogtreecommitdiff
path: root/core/src/reflow/layoutprovider_taggedpdf.cpp
blob: 4a5a22bd614e12269ca75517120d8cee880d290b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
 
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#include "layoutprovider_taggedpdf.h"
CPDF_LayoutElement::CPDF_LayoutElement()
{
    m_pTaggedElement = NULL;
    m_pParentElement = NULL;
}
CPDF_LayoutElement::~CPDF_LayoutElement()
{
    m_ObjArray.RemoveAll();
    int size = m_ChildArray.GetSize();
    for(int i = 0; i < size; i++) {
        CPDF_LayoutElement* pChild = (CPDF_LayoutElement*)m_ChildArray.GetAt(i);
        delete pChild;
        pChild = NULL;
    }
    m_ChildArray.RemoveAll();
}
LayoutType CPDF_LayoutElement::ConvertLayoutType(FX_BSTR name)
{
    if(name == (const char*)("Document")) {
        return LayoutDocument;
    } else if(name == (const char*)("Part")) {
        return LayoutPart;
    } else if(name == (const char*)("Art")) {
        return LayoutArt;
    } else if(name == (const char*)("Sect")) {
        return LayoutSect;
    } else if(name == (const char*)("Div")) {
        return LayoutDiv;
    } else if(name == (const char*)("BlockQuote")) {
        return LayoutBlockQuote;
    } else if(name == (const char*)("Caption")) {
        return LayoutCaption;
    } else if(name == (const char*)("TOC")) {
        return LayoutTOC;
    } else if(name == (const char*)("TOCI")) {
        return LayoutTOCI;
    } else if(name == (const char*)("Index")) {
        return LayoutIndex;
    } else if(name == (const char*)("NonStruct")) {
        return LayoutNonStruct;
    } else if(name == (const char*)("Private")) {
        return LayoutPrivate;
    } else if(name == (const char*)("P")) {
        return LayoutParagraph;
    } else if(name == (const char*)("H")) {
        return LayoutHeading;
    } else if(name == (const char*)("H1")) {
        return LayoutHeading1;
    } else if(name == (const char*)("H2")) {
        return LayoutHeading2;
    } else if(name == (const char*)("H3")) {
        return LayoutHeading3;
    } else if(name == (const char*)("H4")) {
        return LayoutHeading4;
    } else if(name == (const char*)("H5")) {
        return LayoutHeading5;
    } else if(name == (const char*)("H6")) {
        return LayoutHeading6;
    } else if(name == (const char*)("L")) {
        return LayoutList;
    } else if(name == (const char*)("LI")) {
        return LayoutListItem;
    } else if(name == (const char*)("Lbl")) {
        return LayoutListLabel;
    } else if(name == (const char*)("LBody")) {
        return LayoutListBody;
    } else if(name == (const char*)("Table")) {
        return LayoutTable;
    } else if(name == (const char*)("TR")) {
        return LayoutTableRow;
    } else if(name == (const char*)("TH")) {
        return LayoutTableHeaderCell;
    } else if(name == (const char*)("TD")) {
        return LayoutTableDataCell;
    } else if(name == (const char*)("THead")) {
        return LayoutTableHeaderGroup;
    } else if(name == (const char*)("TBody")) {
        return LayoutTableBodyGroup;
    } else if(name == (const char*)("TFoot")) {
        return LayoutTableFootGroup;
    } else if(name == (const char*)("Span")) {
        return LayoutSpan;
    } else if(name == (const char*)("Quote")) {
        return LayoutQuote;
    } else if(name == (const char*)("Note")) {
        return LayoutNote;
    } else if(name == (const char*)("Reference")) {
        return LayoutReference;
    } else if(name == (const char*)("BibEntry")) {
        return LayoutBibEntry;
    } else if(name == (const char*)("Code")) {
        return LayoutCode;
    } else if(name == (const char*)("Link")) {
        return LayoutLink;
    } else if(name == (const char*)("Annot")) {
        return LayoutAnnot;
    } else if(name == (const char*)("Ruby")) {
        return LayoutRuby;
    } else if(name == (const char*)("RB")) {
        return LayoutRubyBase;
    } else if(name == (const char*)("RT")) {
        return LayoutRubyAnnot;
    } else if(name == (const char*)("RP")) {
        return LayoutRubyPunc;
    } else if(name == (const char*)("Warichu")) {
        return LayoutWarichu;
    } else if(name == (const char*)("WT")) {
        return LayoutWarichuText;
    } else if(name == (const char*)("WP")) {
        return LayoutWarichuPunc;
    } else if(name == (const char*)("Figure")) {
        return LayoutFigure;
    } else if(name == (const char*)("Formula")) {
        return LayoutFormula;
    } else if(name == (const char*)("Form")) {
        return LayoutForm;
    } else {
        return LayoutUnknown;
    }
}
CFX_ByteStringC CPDF_LayoutElement::ConvertLayoutType(LayoutType type)
{
    FX_BSTR name = "";
    if(type == LayoutArifact) {
        return "Arifact";
    } else if( type == LayoutDocument) {
        return "Document";
    } else if( type == LayoutPart) {
        return "Part";
    } else if( type == LayoutArt) {
        return "Art";
    } else if( type == LayoutSect) {
        return "Sect";
    } else if( type == LayoutDiv) {
        return "Div";
    } else if( type == LayoutBlockQuote) {
        return "BlockQuote";
    } else if( type == LayoutCaption) {
        return "Caption";
    } else if( type == LayoutTOC) {
        return "TOC";
    } else if( type == LayoutTOCI) {
        return "TOCI";
    } else if( type == LayoutIndex) {
        return "Index";
    } else if( type == LayoutNonStruct) {
        return "NonStruct";
    } else if( type == LayoutPrivate) {
        return "Private";
    } else if( type == LayoutParagraph) {
        return "P";
    } else if( type == LayoutHeading) {
        return "H";
    } else if( type == LayoutHeading1) {
        return "H1";
    } else if( type == LayoutHeading2) {
        return "H2";
    } else if( type == LayoutHeading3) {
        return "H3";
    } else if( type == LayoutHeading4) {
        return "H4";
    } else if( type == LayoutHeading5) {
        return "H5";
    } else if( type == LayoutHeading6) {
        return "H6";
    } else if( type == LayoutList) {
        return "L";
    } else if( type == LayoutListItem) {
        return "LI";
    } else if( type == LayoutListLabel) {
        return "Lbl";
    } else if( type == LayoutListBody) {
        return "LBody";
    } else if( type == LayoutTable) {
        return "Table";
    } else if( type == LayoutTableRow) {
        return "TR";
    } else if( type == LayoutTableHeaderCell) {
        return "TH";
    } else if( type == LayoutTableDataCell) {
        return "TD";
    } else if( type == LayoutTableHeaderGroup) {
        return "THead";
    } else if( type == LayoutTableBodyGroup) {
        return "TBody";
    } else if( type == LayoutTableFootGroup) {
        return "TFoot";
    } else if( type == LayoutSpan) {
        return "Span";
    } else if( type == LayoutQuote) {
        return "Quote";
    } else if( type == LayoutNote) {
        return "Note";
    } else if( type == LayoutReference) {
        return "Reference";
    } else if( type == LayoutBibEntry) {
        return "BibEntry";
    } else if( type == LayoutCode) {
        return "Code";
    } else if( type == LayoutLink) {
        return "Link";
    } else if( type == LayoutAnnot) {
        return "Annot";
    } else if( type == LayoutRuby) {
        return "Ruby";
    } else if( type == LayoutRubyBase) {
        return "RB";
    } else if( type == LayoutRubyAnnot) {
        return "RT";
    } else if( type == LayoutRubyPunc) {
        return "RP";
    } else if( type == LayoutWarichu) {
        return "Warichu";
    } else if( type == LayoutWarichuText) {
        return "WT";
    } else if( type == LayoutWarichuPunc) {
        return "WP";
    } else if( type == LayoutFigure) {
        return "Figure";
    } else if( type == LayoutFormula) {
        return "Formula";
    } else if( type == LayoutForm) {
        return "Form";
    }
    return name;
}
CFX_ByteStringC CPDF_LayoutElement::ConvertLayoutAttr(LayoutAttr attr)
{
    switch(attr) {
        case LayoutArtifactType:
            return "Type";
        case LayoutArtifactAttached:
            return "Attached";
        case LayoutArtifactSubType:
            return "Subtype";
        case LayoutPlacement:
            return "Placement";
        case LayoutWritingMode:
            return "WritingMode";
        case LayoutBackgroundColor:
            return "BackgroundColor";
        case LayoutBorderColor:
            return "BorderColor";
        case LayoutBorderStyle:
            return "BorderStyle";
        case LayoutBorderThickness:
            return "BorderThickness";
        case LayoutPadding:
            return "Padding";
        case LayoutColor:
            return "Color";
        case LayoutSpaceBefore:
            return "SpaceBefore";
        case LayoutSpaceAfter:
            return "SpaceAfter";
        case LayoutStartIndent:
            return "StartIndent";
        case LayoutEndIndent:
            return "EndIndent";
        case LayoutTextIndent:
            return "TextIndent";
        case LayoutTextAlign:
            return "TextAlign";
        case LayoutBBox:
            return "BBox";
        case LayoutWidth:
            return "Width";
        case LayoutHeight:
            return "Height";
        case LayoutBlockAlign:
            return "BlockAlign";
        case LayoutInlineAlign:
            return "InlineAlign";
        case LayoutTBorderStyle:
            return "TBorderStyle";
        case LayoutTPadding:
            return "TPadding";
        case LayoutBaselineShift:
            return "BaselineShift";
        case LayoutLineHeight:
            return "LineHeight";
        case LayoutTextDecorationColor:
            return "TextDecorationColor";
        case LayoutTextDecorationThickness:
            return "TextDecorationThickness";
        case LayoutTextDecorationType:
            return "TextDecorationType";
        case LayoutRubyAlign:
            return "RubyAlign";
        case LayoutRubyPosition:
            return "RubyPosition";
        case LayoutGlyphOrientationVertical:
            return "GlyphOrientationVertical";
        case LayoutColumnCount:
            return "ColumnCount";
        case LayoutColumnGap:
            return "ColumnGap";
        case LayoutColumnWidths:
            return "ColumnWidths";
        case LayoutListNumbering:
            return "ListNumbering";
        case LayoutFieldRole:
            return "Role";
        case LayoutFieldChecked:
            return "checked";
        case LayoutFieldDesc:
            return "Desc";
        case LayoutRowSpan:
            return "RowSpan";
        case LayoutColSpan:
            return "ColSpan";
        case LayoutTableHeaders:
            return "Headers";
        case LayoutTableHeaderScope:
            return "Scope";
        case LayoutTableSummary:
            return "Summary";
        default:
            return "";
    }
}
LayoutEnum CPDF_LayoutElement::ConvertLayoutEnum(CFX_ByteStringC Enum)
{
    if(Enum == "Block") {
        return LayoutBlock;
    } else if (Enum == "Inline") {
        return LayoutInline;
    } else if (Enum == "Before") {
        return LayoutBefore;
    } else if (Enum == "Start") {
        return LayoutStart;
    } else if (Enum == "End") {
        return LayoutEnd;
    } else if (Enum == "LrTb") {
        return LayoutLrTb;
    } else if (Enum == "RlTb") {
        return LayoutRlTb;
    } else if (Enum == "TbRl") {
        return LayoutTbRl;
    } else if (Enum == "None") {
        return LayoutNone;
    } else if (Enum == "Hidden") {
        return LayoutHidden;
    } else if (Enum == "Dotted") {
        return LayoutDotted;
    } else if (Enum == "Dashed") {
        return LayoutDashed;
    } else if (Enum == "Solid") {
        return LayoutSolid;
    } else if (Enum == "Double") {
        return LayoutDouble;
    } else if (Enum == "Groove") {
        return LayoutGroove;
    } else if (Enum == "Ridge") {
        return LayoutRidge;
    } else if (Enum == "Inset") {
        return LayoutInset;
    } else if (Enum == "Outset") {
        return LayoutOutset;
    } else if (Enum == "Normal") {
        return LayoutNormal;
    } else if (Enum == "Auto") {
        return LayoutAuto;
    } else if (Enum == "Center") {
        return LayoutCenter;
    } else if (Enum == "Justify") {
        return LayoutJustify;
    } else if (Enum == "Middle") {
        return LayoutMiddle;
    } else if (Enum == "Underline") {
        return LayoutUnderline;
    } else if (Enum == "Overline") {
        return LayoutOverline;
    } else if (Enum == "LineThrough") {
        return LayoutLineThrough;
    } else if (Enum == "Distribute") {
        return LayoutDistribute;
    } else if (Enum == "Disc") {
        return LayoutDisc;
    } else if (Enum == "Circle") {
        return LayoutCircle;
    } else if (Enum == "Square") {
        return LayoutSquare;
    } else if (Enum == "Decimal") {
        return LayoutDecimal;
    } else if (Enum == "UpperRoman") {
        return LayoutUpperRoman;
    } else if (Enum == "LowerRoman") {
        return LayoutLowerRoman;
    } else if (Enum == "UpperAlpha") {
        return LayoutUpperAlpha;
    } else if (Enum == "LowerAlpha") {
        return LayoutLowerAlpha;
    } else if (Enum == "rb") {
        return LayoutRB;
    } else if (Enum == "cb") {
        return LayoutCB;
    } else if (Enum == "pb") {
        return LayoutPB;
    } else if (Enum == "tv") {
        return LayoutTV;
    } else if (Enum == "on") {
        return LayoutOn;
    } else if (Enum == "off") {
        return LayoutOff;
    } else if (Enum == "neutral") {
        return LayoutNeutral;
    } else if (Enum == "Row") {
        return LayoutRow;
    } else if (Enum == "Column") {
        return LayoutColumn;
    } else if (Enum == "Both") {
        return LayoutBoth;
    } else if (Enum == "Left") {
        return LayoutLeft;
    } else if (Enum == "Top") {
        return LayoutTop;
    } else if (Enum == "Bottom") {
        return LayoutBottom;
    } else if (Enum == "Right") {
        return LayoutRight;
    } else if (Enum == "Pagination") {
        return LayoutPagination;
    } else if (Enum == "Layout") {
        return LayoutLayout;
    } else if (Enum == "Page") {
        return LayoutPage;
    } else if (Enum == "Background") {
        return LayoutBackground;
    } else if (Enum == "Header") {
        return LayoutHeader;
    } else if (Enum == "Footer") {
        return LayoutFooter;
    } else if (Enum == "Watermark") {
        return LayoutWatermark;
    } else {
        return LayoutInvalid;
    }
}
LayoutType CPDF_LayoutElement::GetType()
{
    if(!m_pTaggedElement) {
        return LayoutUnknown;
    }
    CFX_ByteString name = m_pTaggedElement->GetType();
    return this->ConvertLayoutType(name);
}
int	CPDF_LayoutElement::CountAttrValues(LayoutAttr attr_type)
{
    if(!m_pTaggedElement) {
        return 0;
    }
    CPDF_Object* pObj = m_pTaggedElement->GetAttr(GetAttrOwner(attr_type), ConvertLayoutAttr(attr_type), IsInheritable(attr_type));
    if(pObj) {
        return 1;
    } else {
        return 0;
    }
}
LayoutEnum CPDF_LayoutElement::GetEnumAttr(LayoutAttr attr_type, int index)
{
    if(!m_pTaggedElement) {
        return LayoutInvalid;
    }
    CFX_ByteStringC owner = GetAttrOwner(attr_type);
    CFX_ByteStringC default_value = GetDefaultNameValue(attr_type);
    CFX_ByteStringC AttrName = ConvertLayoutAttr(attr_type);
    CFX_ByteString	AttrValue = m_pTaggedElement->GetName(owner, AttrName, default_value, IsInheritable(attr_type), index);
    return ConvertLayoutEnum(AttrValue);
}
CFX_ByteStringC CPDF_LayoutElement::GetAttrOwner(LayoutAttr attr_type)
{
    switch(attr_type) {
        case LayoutListNumbering:
            return "List";
        case LayoutFieldRole:
        case LayoutFieldChecked :
        case LayoutFieldDesc:
            return "PrintField";
        case LayoutRowSpan:
        case LayoutColSpan:
        case LayoutTableHeaders:
        case LayoutTableHeaderScope:
        case LayoutTableSummary:
            return "Table";
        default:
            return "Layout";
    }
}
FX_FLOAT	CPDF_LayoutElement::GetNumberAttr(LayoutAttr attr_type, int index)
{
    if(!m_pTaggedElement) {
        return 0;
    }
    CFX_ByteStringC owner = GetAttrOwner(attr_type);
    FX_FLOAT default_value = GetDefaultFloatValue(attr_type);
    CFX_ByteStringC AttrName = ConvertLayoutAttr(attr_type);
    FX_FLOAT f = m_pTaggedElement->GetNumber(owner, AttrName, default_value, IsInheritable(attr_type), index);
    if(attr_type == LayoutWidth && !f) {
        f = m_pTaggedElement->GetNumber("Table", AttrName, default_value, IsInheritable(attr_type), index);
    }
    return f;
}
FX_COLORREF	CPDF_LayoutElement::GetColorAttr(LayoutAttr attr_type, int index)
{
    if(!m_pTaggedElement) {
        return 0;
    }
    CFX_ByteStringC owner = GetAttrOwner(attr_type);
    FX_COLORREF default_value = GetDefaultColorValue(attr_type);
    CFX_ByteStringC AttrName = ConvertLayoutAttr(attr_type);
    FX_ARGB f = m_pTaggedElement->GetColor(owner, AttrName, default_value, IsInheritable(attr_type), index);
    return f;
}
FX_FLOAT CPDF_LayoutElement::GetDefaultFloatValue(LayoutAttr attr_type)
{
    switch(attr_type) {
        case LayoutColumnCount:
            return 1;
        case LayoutRowSpan:
            return 1;
        case LayoutColSpan:
            return 1;
        default:
            return 0;
    }
}
FX_COLORREF CPDF_LayoutElement::GetDefaultColorValue(LayoutAttr attr_type)
{
    return -1;
}
CFX_ByteStringC CPDF_LayoutElement::GetDefaultNameValue(LayoutAttr attr_type)
{
    switch(attr_type) {
        case LayoutPlacement:
            return "Inline";
        case LayoutWritingMode:
            return "LrTb";
        case LayoutBorderStyle:
            return "None";
        case LayoutTextAlign:
            return "Start";
        case LayoutBlockAlign:
            return "Before";
        case LayoutInlineAlign:
            return "Start";
        case LayoutTBorderStyle:
            return "None";
        case LayoutTextDecorationType:
            return "None";
        case LayoutRubyAlign:
            return "Distribute";
        case LayoutRubyPosition:
            return "Before";
        case LayoutGlyphOrientationVertical:
            return "Auto";
        case LayoutListNumbering:
            return "None";
        case LayoutFieldRole:
            return "None";
        default:
            return "";
    }
}
FX_BOOL	CPDF_LayoutElement::IsInheritable(LayoutAttr type)
{
    switch(type) {
        case LayoutWritingMode:
        case LayoutTextAlign:
        case LayoutBlockAlign:
        case LayoutInlineAlign:
        case LayoutLineHeight:
        case LayoutGlyphOrientationVertical:
        case LayoutRubyAlign:
        case LayoutRubyPosition:
        case LayoutBorderThickness:
        case LayoutStartIndent:
        case LayoutEndIndent:
        case LayoutTextIndent:
        case LayoutTPadding:
        case LayoutTextDecorationThickness:
        case LayoutBorderColor:
        case LayoutColor:
        case LayoutTextDecorationColor:
            return TRUE;
        default:
            return FALSE;
    }
}
int	CPDF_LayoutElement::CountChildren()
{
    return m_ChildArray.GetSize();
}
IPDF_LayoutElement* CPDF_LayoutElement::GetChild(int index)
{
    return (IPDF_LayoutElement*)m_ChildArray.GetAt(index);
}
IPDF_LayoutElement* CPDF_LayoutElement::GetParent()
{
    return m_pParentElement;
}
int	CPDF_LayoutElement::CountObjects()
{
    if(m_pTaggedElement == NULL) {
        return 0;
    }
    CFX_PtrArray* pObj = &m_ObjArray;
    int size = pObj->GetSize();
    return size;
}
CPDF_PageObject* CPDF_LayoutElement::GetObject(int index)
{
    if(m_pTaggedElement == NULL) {
        return NULL;
    }
    CFX_PtrArray *pObj = &m_ObjArray;
    int size = pObj->GetSize();
    if(index < size) {
        return (CPDF_PageObject*)pObj->GetAt(index);
    }
    return NULL;
}
FX_BOOL CPDF_LayoutElement::AddObject(CPDF_PageObject* pObj)
{
    return m_ObjArray.Add(pObj);
}
IPDF_LayoutProvider* IPDF_LayoutProvider::Create_LayoutProvider_TaggedPDF(CPDF_PageObjects* pPage)
{
    if(pPage == NULL) {
        return NULL;
    }
    CPDF_LayoutProvider_TaggedPDF* pProvider = new CPDF_LayoutProvider_TaggedPDF;
    pProvider->Init(pPage);
    return pProvider;
}
CPDF_LayoutProvider_TaggedPDF::CPDF_LayoutProvider_TaggedPDF()
{
    m_pPause = NULL;
    m_pRoot = NULL;
    m_pPageTree = NULL;
    m_pCurTaggedElement = NULL;
}
CPDF_LayoutProvider_TaggedPDF::~CPDF_LayoutProvider_TaggedPDF()
{
    m_pCurTaggedElement = NULL;
    m_pPause = NULL;
    if(m_pRoot) {
        delete m_pRoot;
    }
    m_pRoot = NULL;
    if(m_pPageTree) {
        delete m_pPageTree;
    }
    m_pPageTree = NULL;
}
void CPDF_LayoutProvider_TaggedPDF::ProcessElement(CPDF_LayoutElement*pParent, CPDF_StructElement* pTaggedElement)
{
    if(!pTaggedElement) {
        return;
    }
    if(!pParent) {
        m_Status = LayoutError;
        return;
    }
    CPDF_LayoutElement* pElement = new CPDF_LayoutElement;
    pElement->m_pParentElement = pParent;
    pElement->m_pTaggedElement = pTaggedElement;
    pParent->m_ChildArray.Add(pElement);
    int count = pTaggedElement->CountKids();
    for(int i = 0; i < count; i++) {
        CPDF_StructKid Kid = pTaggedElement->GetKid(i);
        switch(Kid.m_Type) {
            case CPDF_StructKid::Element: {
                    ProcessElement(pElement, Kid.m_Element.m_pElement);
                    if(m_Status != LayoutReady) {
                        return ;
                    }
                }
                break;
            case CPDF_StructKid::PageContent: {
                    int count = m_pPage->CountObjects();
                    FX_POSITION pos = m_pPage->GetFirstObjectPosition();
                    if(!pos) {
                        m_Status = LayoutError;
                        return ;
                    }
                    while (pos) {
                        CPDF_PageObject* pObj = m_pPage->GetNextObject(pos);
                        int pbjMCID = pObj->m_ContentMark.GetMCID();
                        if((FX_DWORD)(pObj->m_ContentMark.GetMCID()) == Kid.m_PageContent.m_ContentId) {
                            pElement->AddObject(pObj);
                        }
                    }
                }
                break;
            case CPDF_StructKid::StreamContent:
            case CPDF_StructKid::Object:
            default:
                break;
        }
    }
}
LayoutStatus CPDF_LayoutProvider_TaggedPDF::StartLoad(IFX_Pause* pPause)
{
    m_pPause = pPause;
    if(m_pPage->m_pDocument && m_pPage->m_pFormDict) {
        m_pPageTree = CPDF_StructTree::LoadPage(m_pPage->m_pDocument, m_pPage->m_pFormDict);
    }
    if(!m_pPageTree) {
        m_Status = LayoutError;
        return LayoutError;
    }
    int count = m_pPageTree->CountTopElements();
    if(count == 0) {
        m_Status = LayoutError;
        return LayoutError;
    }
    m_pRoot = new CPDF_LayoutElement;
    for(int i = 0; i < count; i++) {
        CPDF_StructElement* pElement = m_pPageTree->GetTopElement(i);
        if(pElement) {
            ProcessElement(m_pRoot, pElement);
            if(m_Status != LayoutReady) {
                return m_Status;
            }
        }
    }
    m_pCurTaggedElement = NULL;
    m_Status = LayoutFinished;
    return LayoutFinished;
}
LayoutStatus CPDF_LayoutProvider_TaggedPDF::Continue()
{
    if(!m_pCurTaggedElement) {
        return LayoutError;
    }
    if(m_Status != LayoutToBeContinued) {
        return LayoutError;
    }
    m_Status = LayoutReady;
    int count = m_pPageTree->CountTopElements();
    for(int i = 0; i < count; i++) {
        CPDF_StructElement* pElement = m_pPageTree->GetTopElement(i);
        if(pElement) {
            ProcessElement(m_pRoot, pElement);
            if(m_Status != LayoutReady) {
                return m_Status;
            }
        }
    }
    m_pCurTaggedElement = NULL;
    m_Status = LayoutFinished;
    return LayoutFinished;
}
int CPDF_LayoutProvider_TaggedPDF::GetPosition()
{
    if(m_TopElementIndex == 0) {
        return 0;
    }
    int count = m_pPageTree->CountTopElements();
    return m_TopElementIndex / count * 100;
}