00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 #include "camtypes.h"
00104 #include "xpfrgn.h"
00105
00106
00107 #include "xpfilter.h"
00108 #include "xpfcaps.h"
00109
00110 #include "insertnd.h"
00111
00112 #include "opcntr.h"
00113 #include "lineattr.h"
00114 #include "strkattr.h"
00115 #include "brshattr.h"
00116 #include "vstate.h"
00117 #include "nodepath.h"
00118 #include "nodetxts.h"
00119 #include "nodetext.h"
00120 #include "nodetxtl.h"
00121 #include "grndbmp.h"
00122
00123
00124
00125 CC_IMPLEMENT_DYNAMIC(SpanListItem, ListItem);
00126 CC_IMPLEMENT_DYNAMIC(NodeThreeBoolListItem, ListItem);
00127 CC_IMPLEMENT_DYNAMIC(XPFRenderRegion, RenderRegion);
00128 CC_IMPLEMENT_DYNAMIC(XPFView, View);
00129
00130
00131 #define new CAM_DEBUG_NEW
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 XPFRenderRegion::XPFRenderRegion(PluginNativeFilter* pFilter, CapabilityTree* pPlugCaps, CommonTransInfo* pTransInfo)
00150 {
00151 m_pFilter = pFilter;
00152 m_PixelsPerInch = pPlugCaps ? pPlugCaps->GetRasteriseDPI() : 96.0;
00153 m_pTransInfo = pTransInfo;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 XPFRenderRegion::~XPFRenderRegion()
00170 {
00171 }
00172
00173
00174 BOOL XPFRenderRegion::AttachDevice(View* ViewToAttach, CNativeDC* DCToAttach,
00175 Spread* SpreadToAttach)
00176 {
00177 BOOL ok = RenderRegion::AttachDevice(ViewToAttach, DCToAttach, SpreadToAttach);
00178 if (ok)
00179 {
00180
00181
00182 }
00183
00184 return(ok);
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 BOOL XPFRenderRegion::StartRender()
00203 {
00204
00205 if (!RenderRegion::StartRender())
00206 return FALSE;
00207
00208
00209 return TRUE;
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 BOOL XPFRenderRegion::StopRender()
00224 {
00225 return(TRUE);
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 void XPFRenderRegion::DrawPathToOutputDevice(Path* pPathToRender, PathShape)
00243 {
00244 if (m_pTransInfo && m_pTransInfo->IsCommonType())
00245 {
00246
00247
00248
00249 if (pPathToRender->IsFilled)
00250 {
00251
00252 FillGeometryAttribute* pFillAttr = (FillGeometryAttribute*) CurrentAttrs[ATTR_FILLGEOMETRY].pAttr;
00253
00254
00255
00256 if (!IS_A(pFillAttr, FlatFillAttribute) || !(RR_FILLCOLOUR().IsTransparent()))
00257 {
00258
00259 TranspFillAttribute* pTransAttr = RR_FILLTRANSP();
00260
00261
00262 m_pTransInfo->UpdateCommonType(pTransAttr->GetTranspType());
00263 }
00264 }
00265
00266 if (pPathToRender->IsStroked)
00267 {
00268
00269 if (!(RR_STROKECOLOUR().IsTransparent()))
00270 {
00271
00272 StrokeTranspAttribute* pTransAttr = RR_STROKETRANSP();
00273
00274
00275 m_pTransInfo->UpdateCommonType(pTransAttr->GetTranspType());
00276 }
00277 }
00278 }
00279 }
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 void XPFRenderRegion::DrawRect(DocRect* pRectToRender)
00295 {
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 void XPFRenderRegion::DrawLine(const DocCoord &StartPoint, const DocCoord &EndPoint)
00313 {
00314 }
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 void XPFRenderRegion::DrawPixel(const DocCoord &Point)
00330 {
00331 }
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 void XPFRenderRegion::DrawBitmap(const DocCoord &Point, KernelBitmap* pBitmap)
00348 {
00349 }
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 void XPFRenderRegion::DrawBitmap(const DocCoord &Point, UINT32 BitmapID, UINT32 ToolID)
00368 {
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 BOOL XPFRenderRegion::DrawTransformedBitmap(NodeBitmap *pNodeBitmap)
00385 {
00386 return TRUE;
00387 }
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 void XPFRenderRegion::DrawDragRect(DocRect *RectToRender)
00402 {
00403 }
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418 void XPFRenderRegion::DrawBlob(DocCoord p, BlobType type)
00419 {
00420 }
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 void XPFRenderRegion::DrawCross(const DocCoord &Point, const UINT32 Size)
00436 {
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453 void XPFRenderRegion::DrawBitmapBlob(const DocCoord &Point, KernelBitmap* BlobShape)
00454 {
00455 }
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 void XPFRenderRegion::DrawBitmapBlob(const DocCoord &Point, ResourceID resID)
00471 {
00472 }
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 void XPFRenderRegion::GetRenderRegionCaps(RRCaps* pCaps)
00491 {
00492 pCaps->CanDoAll();
00493 }
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507 void XPFRenderRegion::InitClipping()
00508 {
00509 }
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522 void XPFRenderRegion::InitAttributes()
00523 {
00524 }
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537 void XPFRenderRegion::SetLineAttributes()
00538 {
00539 }
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 void XPFRenderRegion::SetOSDrawingMode()
00553 {
00554 }
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567 void XPFRenderRegion::SetQualityLevel()
00568 {
00569 }
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582 MILLIPOINT XPFRenderRegion::CalcPixelWidth()
00583 {
00584 return MILLIPOINT( 72000.0 / m_PixelsPerInch);
00585 }
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598 MILLIPOINT XPFRenderRegion::CalcScaledPixelWidth()
00599 {
00600 const double dpi = 72000.0 / m_PixelsPerInch;
00601
00602 return (MILLIPOINT)( (dpi / ScaleFactor.MakeDouble()) + 0.5 );
00603 }
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625 XPFRenderCallback::XPFRenderCallback(PluginNativeFilter* pFilter, XPFRenderRegion* pXPFRegion, CapabilityTree* pCapTree, INT32 ConvertPass)
00626 {
00627 m_pFilter = pFilter;
00628 m_pXPFRegion = pXPFRegion;
00629 m_pCapTree = pCapTree;
00630 m_ConvertPass = ConvertPass;
00631 m_pNewSpread = NULL;
00632 m_pContextNode = NULL;
00633 m_Direction = FIRSTCHILD;
00634 m_pSpanParent = NULL;
00635 }
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650 XPFRenderCallback::~XPFRenderCallback()
00651 {
00652 m_ConvertList.DeleteAll();
00653 m_ParentList.DeleteAll();
00654 }
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672 BOOL XPFRenderCallback::BeforeNode(RenderRegion* pRegion, Node* pNode)
00673 {
00674
00675
00676 if (pNode->IsNodeHidden() || pNode->IsAnInsertionNode())
00677 return(FALSE);
00678
00679
00680 switch (m_ConvertPass)
00681 {
00682 case 1:
00683 {
00684
00685 if (m_Direction == FIRSTCHILD)
00686 {
00687
00688
00689
00690 m_Direction = NEXT;
00691 }
00692 else if (m_Direction == NEXT)
00693 {
00694
00695 m_pContextNode = m_pContextNode->FindParent();
00696
00697 }
00698 }
00699 break;
00700
00701 case 2:
00702 {
00703
00704 if (pNode->IsAnObject() && !pNode->IsCompound())
00705 {
00706
00707 XPFConvertType ConvertType = m_pCapTree->GetConvertTypePass2(pNode, m_pXPFRegion);
00708
00709
00710 if (ConvertType == XPFCONVTYPE_STROKED)
00711 {
00712
00713 NodeListItem* pItem = new NodeListItem(pNode);
00714 m_ConvertList.AddTail(pItem);
00715 }
00716 }
00717 }
00718 break;
00719
00720 case 3:
00721 {
00722
00723
00724
00725
00726 if (pNode->IsAnObject())
00727 {
00728
00729 BOOL bFill = FALSE;
00730 BOOL bTrans = FALSE;
00731 BOOL bFillTrans = FALSE;
00732 m_pCapTree->GetConvertTypePass3(pNode, m_pXPFRegion, &bFill, &bTrans, &bFillTrans);
00733
00734
00735 if (bFill || bTrans || bFillTrans)
00736 {
00737
00738 NodeThreeBoolListItem* pItem = new NodeThreeBoolListItem(pNode, bFill, bTrans, bFillTrans);
00739 m_ConvertList.AddTail(pItem);
00740 }
00741 }
00742 }
00743 break;
00744
00745 case 4:
00746 {
00747
00748 if (pNode->IsAnObject())
00749 {
00750
00751 XPFConvertType ConvertType = m_pCapTree->GetConvertTypePass4(pNode, m_pXPFRegion);
00752
00753
00754 if (ConvertType == XPFCONVTYPE_BITMAP)
00755 {
00756
00757 NodeListItem* pItem = new NodeListItem(pNode);
00758 m_ConvertList.AddTail(pItem);
00759 }
00760 }
00761 }
00762 break;
00763
00764 case 5:
00765 {
00766
00767 if (pNode->IsAnObject())
00768 {
00769
00770 Node* pParent = pNode->FindParent();
00771
00772
00773
00774 XPFConvertType ConvertType = m_pCapTree->GetConvertTypePass5(pNode, m_pXPFRegion);
00775
00776
00777 if (pNode->FindFirstChild())
00778 {
00779
00780 if (ConvertType == XPFCONVTYPE_BITMAPSPAN)
00781 {
00782
00783 while (TRUE)
00784 {
00785 SpanListItem* pChildSpanItem = (SpanListItem*)m_ConvertList.GetTail();
00786 if (pChildSpanItem && pChildSpanItem->m_pFirstNode &&
00787 pChildSpanItem->m_pFirstNode->FindParent() == pNode)
00788 {
00789
00790 delete m_ConvertList.RemoveTail();
00791 }
00792 else
00793 {
00794 break;
00795 }
00796 }
00797 }
00798
00799
00800 NodeThreeBoolListItem* pItem = (NodeThreeBoolListItem*)m_ParentList.RemoveTail();
00801
00802 if (pItem)
00803 {
00804
00805 if (pItem->m_pNode == pNode)
00806 {
00807
00808
00809
00810 if (pItem->m_bSecond && !(pItem->m_bFirst))
00811 {
00812 SpanListItem* pChildSpanItem = (SpanListItem*)m_ConvertList.GetTail();
00813 if (pChildSpanItem && pChildSpanItem->m_pFirstNode &&
00814 pChildSpanItem->m_pFirstNode->FindParent() == pNode)
00815 {
00816
00817 delete m_ConvertList.RemoveTail();
00818 }
00819
00820 SpanListItem* pCurItem = (SpanListItem*)m_ConvertList.GetTail();
00821
00822 if (pCurItem && pCurItem->m_pLastNode == pNode->FindPrevious())
00823 {
00824
00825 m_pSpanParent = pCurItem->m_pLastNode->FindParent();
00826 }
00827 else
00828 {
00829
00830 m_pSpanParent = NULL;
00831 }
00832
00833 ConvertType = XPFCONVTYPE_BITMAPSPAN;
00834 }
00835 }
00836 delete pItem;
00837 }
00838 }
00839
00840
00841 if (ConvertType == XPFCONVTYPE_BITMAPSPAN)
00842 {
00843 SpanListItem* pItem = NULL;
00844
00845 if (m_pSpanParent == pParent)
00846 {
00847
00848
00849 pItem = (SpanListItem*)m_ConvertList.GetTail();
00850 if (pItem)
00851 pItem->m_pLastNode = pNode;
00852 }
00853 else
00854 {
00855
00856
00857 pItem = new SpanListItem(pNode);
00858 m_ConvertList.AddTail(pItem);
00859 m_pSpanParent = pParent;
00860 }
00861
00862
00863 if (!pItem->m_bNonAlphaTrans)
00864 {
00865
00866
00867 StrokeTranspAttribute* pStroke = (StrokeTranspAttribute*)(pRegion->GetCurrentAttribute(ATTR_STROKETRANSP));
00868 UINT32 Type = pStroke->GetTranspType();
00869 if (Type != TT_NoTranspType &&
00870 Type != TT_Mix &&
00871 Type != TT_DARKEN &&
00872 Type != TT_LIGHTEN &&
00873 Type != TT_BRIGHTNESS &&
00874 Type != TT_BEVEL)
00875 {
00876
00877 pItem->m_bNonAlphaTrans = TRUE;
00878 }
00879
00880 if (!pItem->m_bNonAlphaTrans)
00881 {
00882 TranspFillAttribute* pFill = (TranspFillAttribute*)(pRegion->GetCurrentAttribute(ATTR_TRANSPFILLGEOMETRY));
00883 UINT32 Type = pFill->GetTranspType();
00884 if (Type != TT_NoTranspType &&
00885 Type != TT_Mix &&
00886 Type != TT_DARKEN &&
00887 Type != TT_LIGHTEN &&
00888 Type != TT_BRIGHTNESS &&
00889 Type != TT_BEVEL)
00890 {
00891
00892 pItem->m_bNonAlphaTrans = TRUE;
00893 }
00894 }
00895 }
00896 }
00897 else
00898 {
00899
00900
00901 m_pSpanParent = NULL;
00902 }
00903
00904 NodeThreeBoolListItem* pParentItem = (NodeThreeBoolListItem*)m_ParentList.GetTail();
00905 if (pParentItem)
00906 {
00907 if (ConvertType == XPFCONVTYPE_BITMAPSPAN)
00908 pParentItem->m_bSecond = TRUE;
00909 else
00910 pParentItem->m_bFirst = TRUE;
00911 }
00912 }
00913 }
00914 break;
00915
00916 default:
00917 {
00918 TRACEUSER( "Gerry", _T("Unimplemented Pass (%d)\n"), m_ConvertPass);
00919 }
00920 break;
00921 }
00922
00923 return(TRUE);
00924 }
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945 BOOL XPFRenderCallback::BeforeSubtree(RenderRegion* pRegion, Node* pNode, Node** ppNextNode, BOOL bClip, SubtreeRenderState* pState)
00946 {
00947
00948
00949
00950
00951
00952 if (pNode->IsNodeHidden() || pNode->IsAnInsertionNode())
00953 return(FALSE);
00954
00955 BOOL ok;
00956 BOOL bSetState = TRUE;
00957 SubtreeRenderState RenderState = SUBTREE_ROOTANDCHILDREN;
00958
00959
00960 switch (m_ConvertPass)
00961 {
00962 case 1:
00963 {
00964
00965
00966
00967 if (m_pCapTree->GetSelection() && pNode->IsAnObject() &&
00968 !(pNode->IsChildOfSelected() || pNode->HasSelectedChildren()))
00969 {
00970 RenderState = SUBTREE_NORENDER;
00971 bSetState = TRUE;
00972 }
00973 else
00974 {
00975
00976
00977
00978
00979 XPFConvertType ConvertType = m_pCapTree->GetConvertTypePass1(pNode, m_pXPFRegion);
00980
00981 if (ConvertType == XPFCONVTYPE_NATIVE)
00982 {
00983
00984
00985
00986
00987
00988
00989 Node* pNodeToAttach = pNode->PublicCopy();
00990
00991
00992
00993 if (m_pContextNode)
00994 {
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007 pNodeToAttach->AttachNode(m_pContextNode, m_Direction);
01008 }
01009
01010
01011 m_pContextNode = pNodeToAttach;
01012 m_Direction = FIRSTCHILD;
01013 }
01014 else if (ConvertType == XPFCONVTYPE_SIMPLE)
01015 {
01016
01017
01018
01019
01020
01021
01022
01023 TRACEUSER( "Gerry", _T("XPFRC# Converting %s to simple\n"), pNode->GetRuntimeClass()->m_lpszClassName);
01024
01025 Node* pNodeToAttach = NULL;
01026 ok = pNode->NodeCopy(&pNodeToAttach);
01027 if (ok && pNodeToAttach)
01028 {
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042 pNodeToAttach->AttachNode(m_pContextNode, m_Direction);
01043
01044
01045 BecomeA BecomeAPath(BECOMEA_REPLACE, CC_RUNTIME_CLASS(NodePath), NULL);
01046 BecomeAPath.SetResultsStayInPlace(TRUE);
01047 ok = pNodeToAttach->DoBecomeA(&BecomeAPath);
01048
01049
01050 if (m_Direction == NEXT)
01051 m_pContextNode = m_pContextNode->FindNext();
01052 else
01053 m_pContextNode = m_pContextNode->FindFirstChild();
01054 m_Direction = NEXT;
01055
01056
01057 RenderState = SUBTREE_NORENDER;
01058 bSetState = TRUE;
01059 }
01060 }
01061 else if (ConvertType == XPFCONVTYPE_BITMAP)
01062 {
01063
01064
01065
01066
01067
01068
01069 BOOL bNonAlphaTrans = DoesNodeUseNonAlphaTrans(pNode);
01070 TRACEUSER("Gerry", _T("XPFRC# Converting %s to bitmap (%s)\n"), pNode->GetRuntimeClass()->m_lpszClassName, bNonAlphaTrans ? _T("NonAlpha") : _T("Alpha"));
01071
01072 Node* pNodeToAttach = RenderNodesToBitmap(pNode, pNode, bNonAlphaTrans);
01073 if (pNodeToAttach)
01074 {
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088 pNodeToAttach->AttachNode(m_pContextNode, m_Direction);
01089
01090
01091 m_pContextNode = pNodeToAttach;
01092 m_Direction = NEXT;
01093 }
01094
01095 RenderState = SUBTREE_NORENDER;
01096 bSetState = TRUE;
01097 }
01098 else if (ConvertType == XPFCONVTYPE_REFORMAT)
01099 {
01100
01101
01102
01103
01104
01105
01106 TRACEUSER( "Gerry", _T("XPFRC# Reformatting %s\n"), pNode->GetRuntimeClass()->m_lpszClassName);
01107
01108 Node* pNodeToAttach = NULL;
01109 if (IS_A(pNode, TextStory))
01110 {
01111
01112 TextStory* pStory = (TextStory*)pNode;
01113 pNodeToAttach = ReformatTextStory(pStory);
01114 if (pNodeToAttach)
01115 {
01116 pNodeToAttach->AttachNode(m_pContextNode, m_Direction);
01117
01118
01119 m_pContextNode = pNodeToAttach;
01120 m_Direction = NEXT;
01121 }
01122 }
01123
01124 RenderState = SUBTREE_NORENDER;
01125 bSetState = TRUE;
01126 }
01127 else if (ConvertType == XPFCONVTYPE_REMOVE)
01128 {
01129
01130
01131
01132
01133 RenderState = SUBTREE_NORENDER;
01134 bSetState = TRUE;
01135 }
01136 }
01137 }
01138 break;
01139
01140 case 2:
01141 {
01142
01143 }
01144 break;
01145
01146 case 3:
01147 {
01148
01149 }
01150 break;
01151
01152 case 4:
01153 {
01154
01155 XPFConvertType ConvertType = m_pCapTree->GetConvertTypePass4(pNode, m_pXPFRegion);
01156
01157 if (ConvertType == XPFCONVTYPE_BITMAP)
01158 {
01159 TRACEUSER( "Gerry", _T("XPFRC# Setting pending bitmap conversion for %s\n"), pNode->GetRuntimeClass()->m_lpszClassName);
01160 NodeListItem* pItem = new NodeListItem(pNode);
01161 m_ConvertList.AddTail(pItem);
01162 RenderState = SUBTREE_NORENDER;
01163 bSetState = TRUE;
01164 }
01165 }
01166 break;
01167
01168 case 5:
01169 {
01170
01171 if (pNode->IsAnObject() && pNode->FindFirstChild())
01172 {
01173
01174
01175 NodeThreeBoolListItem* pItem = new NodeThreeBoolListItem(pNode);
01176 m_ParentList.AddTail(pItem);
01177 }
01178 }
01179 break;
01180
01181 default:
01182 {
01183 TRACEUSER( "Gerry", _T("Unimplemented Pass (%d)\n"), m_ConvertPass);
01184 }
01185 break;
01186 }
01187
01188 if (bSetState)
01189 *pState = RenderState;
01190
01191 return(bSetState);
01192 }
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210 TextStory* XPFRenderCallback::ReformatTextStory(TextStory* pStory)
01211 {
01212
01213 FormatRegion FormattingRegion;
01214 if (FormattingRegion.Init(pStory) == FALSE)
01215 return(NULL);
01216
01217
01218 TextStory* pNewStory = (TextStory*)(pStory->PublicCopy());
01219 if (pNewStory == NULL)
01220 return(NULL);
01221
01222
01223 Node* pContextNode = pNewStory;
01224 AttachNodeDirection Direction = FIRSTCHILD;
01225
01226
01227 Node* pNode = pStory->FindFirstChild();
01228 while (pNode != NULL)
01229 {
01230 Node* pNewNode = NULL;
01231 if (IS_A(pNode, TextLine))
01232 {
01233
01234 pNewNode = ReformatTextLine((TextLine*)pNode, &FormattingRegion);
01235 }
01236 else if (!pNode->IsNodeHidden())
01237 {
01238
01239 if (pNode->IsKindOfTextAttribute())
01240 pNode->Render(&FormattingRegion);
01241
01242
01243 if (!IS_A(pNode, AttrTxtJustification) && !IS_A(pNode, AttrTxtTracking))
01244 pNewNode = pNode->PublicCopy();
01245 }
01246
01247
01248 if (pNewNode)
01249 {
01250 pNewNode->AttachNode(pContextNode, Direction, FALSE, FALSE);
01251
01252
01253 pContextNode = pNewNode;
01254 Direction = NEXT;
01255 }
01256
01257 pNode = pNode->FindNext();
01258 }
01259
01260
01261 pNewStory->SetAutoKerning(FALSE);
01262
01263
01264
01265 return(pNewStory);
01266 }
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285 Node* XPFRenderCallback::ReformatTextLine(TextLine* pLineNode, FormatRegion* pFormatRegion)
01286 {
01287
01288
01289 BOOL ok = TRUE;
01290
01291
01292 Node* pNewRoot = pLineNode->PublicCopy();
01293
01294
01295 Node* pContextNode = pNewRoot;
01296 AttachNodeDirection Direction = FIRSTCHILD;
01297
01298 pFormatRegion->SaveContext();
01299
01300
01301 MILLIPOINT CurrentPosMP = 0;
01302
01303
01304 Node* pNode = pLineNode->FindFirstChild();
01305 while (pNode != NULL)
01306 {
01307
01308 Node* pNewNode = NULL;
01309 if (pNode->IsAnAbstractTextChar())
01310 {
01311 VisibleTextNode* pVTN=(VisibleTextNode*)pNode;
01312 AbstractTextChar* pATC=(AbstractTextChar*)pNode;
01313
01314
01315
01316 pFormatRegion->SaveContext();
01317
01318 Node* pChildNode = pNode->FindFirstChild();
01319 while (pChildNode != NULL)
01320 {
01321 if (pChildNode->IsKindOfTextAttribute())
01322 pChildNode->Render(pFormatRegion);
01323
01324 pChildNode = pChildNode->FindNext();
01325 }
01326
01327
01328
01329 CharMetrics CharMet;
01330 ok = pFormatRegion->GetCharMetrics(&CharMet, pATC->GetUnicodeValue());
01331
01332
01333
01334 if (!pVTN->IsASpace())
01335 {
01336
01337 MILLIPOINT PosMP = pVTN->GetPosInLine();
01338
01339
01340 if (PosMP != CurrentPosMP)
01341 {
01342
01343 INT32 PosEM1000 = MulDiv(PosMP - CurrentPosMP, 1000, CharMet.FontEmWidth);
01344
01345
01346 INT32 KernSizeMP = MulDiv(PosEM1000, CharMet.FontEmWidth, 1000);
01347
01348
01349
01350
01351 if (KernSizeMP > (PosMP - CurrentPosMP))
01352 PosEM1000 -= 1;
01353
01354
01355 DocCoord TempCoord(PosEM1000, 0);
01356 KernCode* pKern = new KernCode(TempCoord);
01357 if (pKern)
01358 {
01359 ok = CopyAttributesFromNode(pKern, pNode);
01360 pKern->AttachNode(pContextNode, Direction, FALSE, FALSE);
01361 pContextNode = pKern;
01362 Direction = NEXT;
01363 }
01364 CurrentPosMP = PosMP;
01365 }
01366 }
01367
01368
01369
01370 CurrentPosMP += pATC->GetCharWidth();
01371
01372
01373 pNewNode = pNode->PublicCopy();
01374 if (pNewNode)
01375 {
01376 ok = CopyAttributesFromNode(pNewNode, pNode);
01377 pNewNode->AttachNode(pContextNode, Direction, FALSE, FALSE);
01378 pContextNode = pNewNode;
01379 Direction = NEXT;
01380 pNewNode = NULL;
01381 }
01382
01383 pFormatRegion->RestoreContext();
01384 }
01385 else if(!pNode->IsNodeHidden())
01386 {
01387 if (pNode->IsKindOfTextAttribute())
01388 pNode->Render(pFormatRegion);
01389
01390 if (!IS_A(pNode, AttrTxtJustification) && !IS_A(pNode, AttrTxtTracking))
01391 pNewNode = pNode->PublicCopy();
01392
01393 if (pNewNode)
01394 {
01395 ok = CopyAttributesFromNode(pNewNode, pNode);
01396 pNewNode->AttachNode(pContextNode, Direction, FALSE, FALSE);
01397 pContextNode = pNewNode;
01398 Direction = NEXT;
01399 }
01400 }
01401
01402 pNode = pNode->FindNext();
01403 }
01404
01405 pFormatRegion->RestoreContext();
01406
01407 return(pNewRoot);
01408 }
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427 BOOL XPFRenderCallback::CopyAttributesFromNode(Node* pDestNode, Node* pSrcNode)
01428 {
01429 Node* pChildNode = pSrcNode->FindFirstChild();
01430 Node* pContextNode = pDestNode;
01431 AttachNodeDirection Direction = FIRSTCHILD;
01432 while (pChildNode)
01433 {
01434 if (!pChildNode->IsNodeHidden() && !IS_A(pChildNode, AttrTxtJustification) && !IS_A(pChildNode, AttrTxtTracking))
01435 {
01436 Node* pNewChild = pChildNode->PublicCopy();
01437 if (pNewChild)
01438 {
01439 pNewChild->AttachNode(pContextNode, Direction, FALSE, FALSE);
01440 pContextNode = pNewChild;
01441 Direction = NEXT;
01442 }
01443 }
01444
01445 pChildNode = pChildNode->FindNext();
01446 }
01447
01448 return(TRUE);
01449 }
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466 void XPFRenderCallback::RemoveChildAttrs(Node* pNode, CCRuntimeClass* pClass)
01467 {
01468 Node* pChild = pNode->FindFirstChild();
01469 while (pChild)
01470 {
01471 Node* pNextChild = pChild->FindNext();
01472 if (pChild->IsAnAttribute())
01473 {
01474 NodeAttribute* pAttr = (NodeAttribute*)pChild;
01475 if (pAttr->GetAttributeType() == pClass)
01476 {
01477 pChild->CascadeDelete();
01478 delete pChild;
01479 }
01480 }
01481 pChild = pNextChild;
01482 }
01483 }
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501 NodeAttribute* XPFRenderCallback::FindChildAttr(Node* pNode, CCRuntimeClass* pClass)
01502 {
01503 Node* pChild = pNode->FindLastChild();
01504 while (pChild)
01505 {
01506 if (pChild->IsAnAttribute())
01507 {
01508 NodeAttribute* pAttr = (NodeAttribute*)pChild;
01509 if (pAttr->GetAttributeType() == pClass)
01510 {
01511 return(pAttr);
01512 }
01513 }
01514 pChild = pChild->FindPrevious();
01515 }
01516 return(NULL);
01517 }
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535 BOOL XPFRenderCallback::DoesNodeUseNonAlphaTrans(Node* pRootNode)
01536 {
01537
01538
01539
01540
01541
01542
01543
01544
01545 if (pRootNode->IsAnObject())
01546 {
01547 NodeRenderableInk* pInkNode = (NodeRenderableInk*)pRootNode;
01548
01549
01550
01551 AttrStrokeTransp* pStrkAttr = (AttrStrokeTransp*)(pInkNode->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrStrokeTransp), TRUE));
01552 if (pStrkAttr)
01553 {
01554 UINT32 Type = pStrkAttr->GetTranspType();
01555 if (Type != TT_NoTranspType &&
01556 Type != TT_Mix &&
01557 Type != TT_DARKEN &&
01558 Type != TT_LIGHTEN &&
01559 Type != TT_BRIGHTNESS &&
01560 Type != TT_BEVEL)
01561 {
01562 return(TRUE);
01563 }
01564 }
01565
01566 AttrFillGeometry* pFillAttr = (AttrFillGeometry*)(pInkNode->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrTranspFillGeometry), TRUE));
01567 if (pFillAttr)
01568 {
01569 UINT32 Type = pFillAttr->GetTranspType();
01570 if (Type != TT_NoTranspType &&
01571 Type != TT_Mix &&
01572 Type != TT_DARKEN &&
01573 Type != TT_LIGHTEN &&
01574 Type != TT_BRIGHTNESS &&
01575 Type != TT_BEVEL)
01576 {
01577 return(TRUE);
01578 }
01579 }
01580 }
01581
01582
01583 Node* pNode = pRootNode->FindFirstDepthFirst();
01584 while (pNode)
01585 {
01586
01587 if (pNode->IsAnAttribute() && pNode->IS_KIND_OF(AttrFillGeometry))
01588 {
01589 AttrFillGeometry* pAttr = (AttrFillGeometry*)pNode;
01590 UINT32 Type = pAttr->GetTranspType();
01591 if (Type != TT_NoTranspType &&
01592 Type != TT_Mix &&
01593 Type != TT_DARKEN &&
01594 Type != TT_LIGHTEN &&
01595 Type != TT_BRIGHTNESS &&
01596 Type != TT_BEVEL)
01597 {
01598 return(TRUE);
01599 }
01600 }
01601
01602
01603 pNode = pNode->FindNextDepthFirst(pRootNode);
01604 }
01605
01606 return(FALSE);
01607 }
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623 BOOL XPFRenderCallback::ConvertNodes()
01624 {
01625 BOOL ok = TRUE;
01626 switch (m_ConvertPass)
01627 {
01628 case 2:
01629 ok = ConvertNodesForPass2();
01630 break;
01631
01632 case 3:
01633 ok = ConvertNodesForPass3();
01634 break;
01635
01636 case 4:
01637 ok = ConvertNodesForPass4();
01638 break;
01639
01640 case 5:
01641 ok = ConvertNodesForPass5();
01642 break;
01643
01644 default:
01645 break;
01646 }
01647
01648
01649 m_ConvertList.DeleteAll();
01650
01651 return(ok);
01652 }
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668 BOOL XPFRenderCallback::ConvertNodesForPass2()
01669 {
01670 TRACEUSER( "Gerry", _T("ConvertNodesForPass2 (%d)\n"), m_ConvertList.GetCount());
01671
01672 double dProgress = 0.0;
01673 double dInc = 100.0 / (double)m_ConvertList.GetCount();
01674
01675 BOOL ok = TRUE;
01676 NodeListItem* pItem = (NodeListItem*)m_ConvertList.GetHead();
01677 while (pItem)
01678 {
01679 Node* pNode = pItem->pNode;
01680 NodeRenderableInk* pInkNode = (NodeRenderableInk*)pNode;
01681
01682 TRACEUSER( "Gerry", _T("ConvertStroked 0x%08x (%s) \n"), pNode, pNode->GetRuntimeClass()->m_lpszClassName);
01683
01684
01685
01686 NodeAttribute* pStrokeCol = NULL;
01687 pInkNode->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrStrokeColour), &pStrokeCol);
01688 if (pStrokeCol && !((AttrStrokeColour*)pStrokeCol)->Value.GetStartColour()->IsTransparent())
01689 {
01690
01691
01692
01693
01694
01695
01696
01697 BOOL bHasFill = TRUE;
01698 if (pNode->IsKindOf(CC_RUNTIME_CLASS(NodePath)))
01699 {
01700 NodePath* pPath = (NodePath*)pNode;
01701 if (!pPath->InkPath.IsFilled)
01702 bHasFill = FALSE;
01703 }
01704
01705 if (bHasFill)
01706 {
01707 NodeAttribute* pAppliedAttr = NULL;
01708 pInkNode->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrFillGeometry), &pAppliedAttr);
01709 if (pAppliedAttr != NULL && IS_A(pAppliedAttr, AttrFlatColourFill))
01710 {
01711 DocColour* pLineColour = ((AttrFlatColourFill*)pAppliedAttr)->GetStartColour();
01712 if (pLineColour != NULL)
01713 if (pLineColour->IsTransparent())
01714 bHasFill = FALSE;
01715 }
01716 }
01717
01718 if (bHasFill)
01719 {
01720
01721 NodeGroup* pGroup = new NodeGroup(pNode, NEXT);
01722 if (pGroup == NULL)
01723 {
01724
01725 return(FALSE);
01726 }
01727
01728 Node* pFillNode = NULL;
01729
01730
01731 ok = pNode->NodeCopy((Node**)&pFillNode);
01732 if (!ok)
01733 {
01734
01735 return(ok);
01736 }
01737
01738 pFillNode->AttachNode(pGroup, FIRSTCHILD);
01739
01740
01741 pNode->MoveNode(pFillNode, NEXT);
01742
01743
01744 ok = OpConvertPathToShapes::ConvertPathToShapes(NULL, (NodeRenderableInk*)pNode);
01745 TRACEUSER( "Gerry", _T("ConvertPathToShapes returned %s\n"), ok ? _T("true") : _T("false"));
01746 if (!ok)
01747 {
01748
01749 return(ok);
01750 }
01751
01752
01753 pGroup->LocaliseCommonAttributes(FALSE, TRUE, NULL);
01754
01755
01756 RemoveChildAttrs(pFillNode, CC_RUNTIME_CLASS(AttrStrokeColour));
01757 RemoveChildAttrs(pFillNode, CC_RUNTIME_CLASS(AttrStrokeTransp));
01758 RemoveChildAttrs(pFillNode, CC_RUNTIME_CLASS(AttrDashPattern));
01759 RemoveChildAttrs(pFillNode, CC_RUNTIME_CLASS(AttrStartArrow));
01760 RemoveChildAttrs(pFillNode, CC_RUNTIME_CLASS(AttrEndArrow));
01761 RemoveChildAttrs(pFillNode, CC_RUNTIME_CLASS(AttrStartCap));
01762 RemoveChildAttrs(pFillNode, CC_RUNTIME_CLASS(AttrLineWidth));
01763 RemoveChildAttrs(pFillNode, CC_RUNTIME_CLASS(AttrVariableWidth));
01764 RemoveChildAttrs(pFillNode, CC_RUNTIME_CLASS(AttrBrushType));
01765 RemoveChildAttrs(pFillNode, CC_RUNTIME_CLASS(AttrStrokeType));
01766
01767
01768 AttrStrokeColour* pTranspAttr = new AttrStrokeColour(pFillNode, FIRSTCHILD);
01769 if (pTranspAttr)
01770 {
01771 StrokeColourAttribute* pTranspVal = (StrokeColourAttribute*)(pTranspAttr->GetAttributeValue());
01772 pTranspVal->Colour = DocColour(COLOUR_NONE);
01773 }
01774
01775 pGroup->FactorOutCommonChildAttributes(TRUE, (AttrTypeSet*)NULL);
01776 }
01777 else
01778 {
01779 ok = OpConvertPathToShapes::ConvertPathToShapes(NULL, (NodeRenderableInk*)pNode);
01780 TRACEUSER( "Gerry", _T("ConvertPathToShapes returned %s\n"), ok ? _T("true") : _T("false"));
01781 if (!ok)
01782 {
01783 return(ok);
01784 }
01785 }
01786 }
01787 else
01788 {
01789 TRACEUSER( "Gerry", _T("No line colour\n"));
01790 }
01791
01792
01793 pItem = (NodeListItem*)m_ConvertList.GetNext(pItem);
01794
01795 dProgress += dInc;
01796 if (!m_pFilter->SetProgressBarCount((UINT32)dProgress))
01797 {
01798 Error::SetError(_R(IDN_USER_CANCELLED),0);
01799 return(FALSE);
01800 }
01801 }
01802
01803 return(TRUE);
01804 }
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821 BOOL XPFRenderCallback::ConvertNodesForPass3()
01822 {
01823 TRACEUSER( "Gerry", _T("ConvertNodesForPass3 (%d)\n"), m_ConvertList.GetCount());
01824
01825 double dProgress = 0.0;
01826 double dInc = 100.0 / (double)m_ConvertList.GetCount();
01827
01828 NodeCompound* pLastParent = NULL;
01829 NodeThreeBoolListItem* pItem = (NodeThreeBoolListItem*)m_ConvertList.GetHead();
01830 while (pItem)
01831 {
01832 TRACEUSER( "Gerry", _T("ConvertFillAttrs 0x%08x (%s) %s%s\n"), pItem->m_pNode, pItem->m_pNode->GetRuntimeClass()->m_lpszClassName, pItem->m_bFirst ? _T("fill ") : _T(""), pItem->m_bSecond ? _T("trans") : _T(""));
01833 Node* pNode = pItem->m_pNode;
01834 Node* pParentNode = pNode->FindParent();
01835 ERROR2IF(!pParentNode, FALSE, "Node has no parent in ConvertNodesForPass3");
01836
01837 NodeCompound* pParent = NULL;
01838 if (pParentNode->IsCompound())
01839 {
01840 pParent = (NodeCompound*)pParentNode;
01841 if (pParent != pLastParent)
01842 {
01843 if (pLastParent)
01844 pLastParent->FactorOutCommonChildAttributes(TRUE, (AttrTypeSet*)NULL);
01845
01846 pParent->LocaliseCommonAttributes(TRUE, TRUE, NULL);
01847 pLastParent = pParent;
01848 }
01849 }
01850
01851 NodeRenderableBounded* pTheNode = (NodeRenderableBounded*)pNode;
01852 DocRect BoundsRect = pTheNode->GetBoundingRect(TRUE, FALSE);
01853
01854 if (pItem->m_bThird)
01855 {
01856
01857
01858
01859 KernelBitmap* pBmp = RenderFillAndTransToBitmap(pNode, BoundsRect);
01860 if (!pBmp)
01861 return(FALSE);
01862
01863
01864 RemoveChildAttrs(pNode, CC_RUNTIME_CLASS(AttrFillGeometry));
01865 RemoveChildAttrs(pNode, CC_RUNTIME_CLASS(AttrFillMapping));
01866 RemoveChildAttrs(pNode, CC_RUNTIME_CLASS(AttrFillEffect));
01867 RemoveChildAttrs(pNode, CC_RUNTIME_CLASS(AttrTranspFillMapping));
01868 RemoveChildAttrs(pNode, CC_RUNTIME_CLASS(AttrTranspFillGeometry));
01869
01870
01871 AttrBitmapColourFill* pBmpFill = new AttrBitmapColourFill(pNode, FIRSTCHILD);
01872 if (!pBmpFill)
01873 {
01874 delete pBmp;
01875 return(FALSE);
01876 }
01877
01878 BitmapFillAttribute* pBmpVal = (BitmapFillAttribute*)(pBmpFill->GetAttributeValue());
01879 pBmpVal->BitmapRef.Attach(pBmp);
01880 DocCoord BottomLeft(BoundsRect.lo);
01881 DocCoord BottomRight(BoundsRect.hi.x, BoundsRect.lo.y);
01882 DocCoord TopLeft(BoundsRect.lo.x, BoundsRect.hi.y);
01883 pBmpVal->SetStartPoint(&BottomLeft);
01884 pBmpVal->SetEndPoint(&BottomRight);
01885 pBmpVal->SetEndPoint2(&TopLeft);
01886
01887
01888 AttrFillMappingLinear* pFillMap = new AttrFillMappingLinear(pNode, FIRSTCHILD);
01889 if (!pFillMap)
01890 {
01891 delete pBmpFill;
01892 return(FALSE);
01893 }
01894
01895 FillMappingLinearAttribute* pMapVal = (FillMappingLinearAttribute*)(pFillMap->GetAttributeValue());
01896 pMapVal->Repeat = 1;
01897 }
01898 else
01899 {
01900 if (pItem->m_bFirst)
01901 {
01902
01903
01904
01905 KernelBitmap* pBmp = RenderFillToBitmap(pNode, BoundsRect);
01906 if (!pBmp)
01907 return(FALSE);
01908
01909
01910 RemoveChildAttrs(pNode, CC_RUNTIME_CLASS(AttrFillGeometry));
01911 RemoveChildAttrs(pNode, CC_RUNTIME_CLASS(AttrFillMapping));
01912 RemoveChildAttrs(pNode, CC_RUNTIME_CLASS(AttrFillEffect));
01913
01914
01915 AttrBitmapColourFill* pBmpFill = new AttrBitmapColourFill(pNode, FIRSTCHILD);
01916 if (!pBmpFill)
01917 {
01918 delete pBmp;
01919 return(FALSE);
01920 }
01921
01922 BitmapFillAttribute* pBmpVal = (BitmapFillAttribute*)(pBmpFill->GetAttributeValue());
01923 pBmpVal->BitmapRef.Attach(pBmp);
01924 DocCoord BottomLeft(BoundsRect.lo);
01925 DocCoord BottomRight(BoundsRect.hi.x, BoundsRect.lo.y);
01926 DocCoord TopLeft(BoundsRect.lo.x, BoundsRect.hi.y);
01927 pBmpVal->SetStartPoint(&BottomLeft);
01928 pBmpVal->SetEndPoint(&BottomRight);
01929 pBmpVal->SetEndPoint2(&TopLeft);
01930
01931
01932 AttrFillMappingLinear* pFillMap = new AttrFillMappingLinear(pNode, FIRSTCHILD);
01933 if (!pFillMap)
01934 {
01935 delete pBmpFill;
01936 return(FALSE);
01937 }
01938
01939 FillMappingLinearAttribute* pMapVal = (FillMappingLinearAttribute*)(pFillMap->GetAttributeValue());
01940 pMapVal->Repeat = 1;
01941 }
01942
01943 if (pItem->m_bSecond)
01944 {
01945
01946
01947
01948
01949 UINT32 TransType = 0;
01950 KernelBitmap* pBmp = RenderTransToBitmap(pNode, BoundsRect, &TransType);
01951 if (!pBmp)
01952 return(FALSE);
01953
01954
01955
01956 NodeAttribute* pOldGeometry = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrTranspFillGeometry));
01957
01958
01959 AttrBitmapTranspFill* pBmpTrans = NULL;
01960 if (pOldGeometry)
01961 pBmpTrans = new AttrBitmapTranspFill(pOldGeometry, NEXT);
01962 else
01963 pBmpTrans = new AttrBitmapTranspFill(pNode, FIRSTCHILD);
01964 if (!pBmpTrans)
01965 {
01966 delete pBmp;
01967 return(FALSE);
01968 }
01969
01970 BitmapTranspFillAttribute* pBmpVal = (BitmapTranspFillAttribute*)(pBmpTrans->GetAttributeValue());
01971 pBmpVal->BitmapRef.Attach(pBmp);
01972 DocCoord BottomLeft(BoundsRect.lo);
01973 DocCoord BottomRight(BoundsRect.hi.x, BoundsRect.lo.y);
01974 DocCoord TopLeft(BoundsRect.lo.x, BoundsRect.hi.y);
01975 pBmpVal->SetStartPoint(&BottomLeft);
01976 pBmpVal->SetEndPoint(&BottomRight);
01977 pBmpVal->SetEndPoint2(&TopLeft);
01978 UINT32 Val = 0;
01979 pBmpVal->SetStartTransp(&Val);
01980 Val = 255;
01981 pBmpVal->SetEndTransp(&Val);
01982 pBmpVal->SetTranspType(TransType);
01983
01984
01985 NodeAttribute* pOldMapping = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrTranspFillMapping));
01986
01987
01988 if (pOldGeometry)
01989 {
01990
01991 if (pOldMapping && pOldMapping->IsEffectAttribute() != pOldGeometry->IsEffectAttribute())
01992 pOldMapping = NULL;
01993 }
01994
01995
01996 AttrTranspFillMappingLinear* pTransMap = NULL;
01997 if (pOldMapping)
01998 pTransMap = new AttrTranspFillMappingLinear(pOldMapping, NEXT);
01999 else if (pOldGeometry)
02000 pTransMap = new AttrTranspFillMappingLinear(pOldGeometry, NEXT);
02001 else
02002 pTransMap = new AttrTranspFillMappingLinear(pNode, FIRSTCHILD);
02003 if (!pTransMap)
02004 {
02005 delete pBmpTrans;
02006 return(FALSE);
02007 }
02008
02009 TranspFillMappingLinearAttribute* pMapVal = (TranspFillMappingLinearAttribute*)(pTransMap->GetAttributeValue());
02010 pMapVal->Repeat = 1;
02011
02012
02013 if (pOldGeometry)
02014 {
02015 pOldGeometry->CascadeDelete();
02016 delete pOldGeometry;
02017 }
02018 if (pOldMapping)
02019 {
02020 pOldMapping->CascadeDelete();
02021 delete pOldMapping;
02022 }
02023 }
02024 }
02025
02026 dProgress += dInc;
02027 if (!m_pFilter->SetProgressBarCount((UINT32)dProgress))
02028 {
02029 Error::SetError(_R(IDN_USER_CANCELLED),0);
02030 return(FALSE);
02031 }
02032
02033 pItem = (NodeThreeBoolListItem*)m_ConvertList.GetNext(pItem);
02034 }
02035
02036 if (pLastParent)
02037 pLastParent->FactorOutCommonChildAttributes(TRUE, (AttrTypeSet*)NULL);
02038
02039 return(TRUE);
02040 }
02041
02042
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056 BOOL XPFRenderCallback::ConvertNodesForPass4()
02057 {
02058 TRACEUSER( "Gerry", _T("ConvertNodesForPass4 (%d)\n"), m_ConvertList.GetCount());
02059
02060 double dProgress = 0.0;
02061 double dInc = 100.0 / (double)m_ConvertList.GetCount();
02062
02063 NodeListItem* pItem = (NodeListItem*)m_ConvertList.GetHead();
02064 while (pItem)
02065 {
02066 Node* pNode = pItem->pNode;
02067 if (pNode)
02068 {
02069 TRACEUSER( "Gerry", _T("NodeListItem 0x%08x (%s)\n"), pNode, pNode->GetRuntimeClass()->m_lpszClassName);
02070
02071
02072 BOOL bNonAlphaTrans = DoesNodeUseNonAlphaTrans(pNode);
02073 Node* pNewNode = RenderNodesToBitmap(pNode, pNode, bNonAlphaTrans);
02074 if (!pNewNode)
02075 return(FALSE);
02076
02077
02078 pNewNode->AttachNode(pNode, PREV);
02079
02080
02081 pNode->CascadeDelete();
02082 delete pNode;
02083 }
02084
02085 dProgress += dInc;
02086 if (!m_pFilter->SetProgressBarCount((UINT32)dProgress))
02087 {
02088 Error::SetError(_R(IDN_USER_CANCELLED),0);
02089 return(FALSE);
02090 }
02091
02092
02093 pItem = (NodeListItem*)m_ConvertList.GetNext(pItem);
02094 }
02095
02096 return(TRUE);
02097 }
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113 BOOL XPFRenderCallback::ConvertNodesForPass5()
02114 {
02115 TRACEUSER( "Gerry", _T("ConvertNodesForPass5 (%d)\n"), m_ConvertList.GetCount());
02116
02117 double dProgress = 0.0;
02118 double dInc = 100.0 / (double)m_ConvertList.GetCount();
02119
02120 SpanListItem* pItem = (SpanListItem*)m_ConvertList.GetHead();
02121 while (pItem)
02122 {
02123 TRACEUSER( "Gerry", _T("SpanListItem 0x%08x (%s) to 0x%08x (%s)\n"), pItem->m_pFirstNode, pItem->m_pFirstNode->GetRuntimeClass()->m_lpszClassName, pItem->m_pLastNode, pItem->m_pLastNode->GetRuntimeClass()->m_lpszClassName);
02124
02125
02126 Node* pNewNode = RenderNodesToBitmap(pItem->m_pFirstNode, pItem->m_pLastNode, pItem->m_bNonAlphaTrans);
02127 if (!pNewNode)
02128 return(FALSE);
02129
02130
02131 pNewNode->AttachNode(pItem->m_pFirstNode, PREV);
02132
02133
02134 Node* pNode = pItem->m_pFirstNode;
02135 while (pNode)
02136 {
02137 Node* pNextNode = (pNode == pItem->m_pLastNode) ? NULL : pNode->FindNext();
02138
02139 pNode->CascadeDelete();
02140 delete pNode;
02141
02142 pNode = pNextNode;
02143 }
02144
02145 dProgress += dInc;
02146 if (!m_pFilter->SetProgressBarCount((UINT32)dProgress))
02147 {
02148 Error::SetError(_R(IDN_USER_CANCELLED),0);
02149 return(FALSE);
02150 }
02151
02152
02153 pItem = (SpanListItem*)m_ConvertList.GetNext(pItem);
02154 }
02155
02156 return(TRUE);
02157 }
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175 BOOL XPFRenderCallback::FindCommonTransTypeToApply(Node* pFirstNode, Node* pLastNode, UINT32* pCommonType)
02176 {
02177
02178 if (!m_pCapTree->HasRasteriseCommonTrans())
02179 return(FALSE);
02180
02181
02182
02183 View *pView = View::GetCurrent();
02184 Spread* pSpread = pFirstNode->FindParentSpread();;
02185
02186 CommonTransInfo TransInfo;
02187
02188
02189 XPFRenderRegion XPFRegion(NULL, NULL, &TransInfo);
02190
02191
02192
02193 XPFRegion.AttachDevice(pView, NULL, pSpread);
02194
02195
02196 if (XPFRegion.StartRender())
02197 {
02198 TRACEUSER( "Gerry", _T("Rendering nodes from 0x%08x to 0x%08x\n"), pFirstNode, pLastNode);
02199 XPFSpanRenderCallback SpanCallback(pFirstNode, pLastNode, FALSE);
02200
02201 XPFRegion.RenderTree(pSpread, FALSE, FALSE, &SpanCallback);
02202
02203
02204 XPFRegion.StopRender();
02205
02206
02207 if (TransInfo.IsCommonType())
02208 {
02209 UINT32 CommonType = TransInfo.GetCommonType();
02210 if (CommonType != TT_Mix)
02211 {
02212 *pCommonType = CommonType;
02213 return(TRUE);
02214 }
02215 }
02216 else
02217 {
02218 if (TransInfo.UsesNonAlpha())
02219 {
02220 if (pFirstNode == pLastNode && IS_A(pFirstNode, Layer))
02221 {
02222 Layer* pLayer = (Layer*)pFirstNode;
02223 String_256 LayerName = pLayer->GetLayerID();
02224 String_256 WarningMsg;
02225 WarningMsg.MakeMsg(_R(IDS_XPF_MIXEDTRANSLAYER), &LayerName);
02226 Error::SetError(_R(IDS_XPF_MIXEDTRANSLAYER),WarningMsg,0);
02227 InformWarning();
02228 }
02229 }
02230 }
02231 }
02232 else
02233 {
02234 ERROR2(FALSE, "StartRender failed");
02235 }
02236
02237 return(FALSE);
02238 }
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259 Node* XPFRenderCallback::RenderNodesToBitmap(Node* pFirstNode, Node* pLastNode, BOOL bNonAlphaTrans)
02260 {
02261
02262 BOOL bOldLayerVisibility = FALSE;
02263 Layer* pSingleLayer = NULL;
02264 Spread* pSingleSpread = NULL;
02265 NodeBitmap* pSingleBitmap = NULL;
02266 if (pFirstNode == pLastNode)
02267 {
02268 if (pFirstNode->IsLayer())
02269 {
02270 pSingleLayer = (Layer*)pFirstNode;
02271 bOldLayerVisibility = pSingleLayer->GetVisibleFlagState();
02272 pSingleLayer->SetVisible(TRUE);
02273 }
02274 else if (pFirstNode->IsSpread())
02275 {
02276 pSingleSpread = (Spread*)pFirstNode;
02277 }
02278 else if (pFirstNode->IsABitmap())
02279 {
02280 pSingleBitmap = (NodeBitmap*)pFirstNode;
02281 }
02282 }
02283
02284
02285
02286 DocRect SpanBounds;
02287 BOOL bBackground = FALSE;
02288 BOOL bForceMix = FALSE;
02289 BOOL bAlpha = m_pCapTree->GetRasteriseAlpha();
02290 UINT32 TransToApply = TT_NoTranspType;
02291 if (!bAlpha)
02292 {
02293 bBackground = TRUE;
02294 }
02295 else
02296 {
02297 if (FindCommonTransTypeToApply(pFirstNode, pLastNode, &TransToApply))
02298 {
02299 bBackground = FALSE;
02300 bForceMix = TRUE;
02301 }
02302 else
02303 {
02304 bBackground = bNonAlphaTrans;
02305 }
02306 }
02307
02308 Node* pNode = pFirstNode;
02309 while (pNode)
02310 {
02311 if (pNode->IsBounded())
02312 {
02313 DocRect ObjectRect = ((NodeRenderableBounded*)pNode)->GetBoundingRect(FALSE, FALSE);
02314 SpanBounds = SpanBounds.Union(ObjectRect);
02315 }
02316
02317 if (pNode == pLastNode)
02318 break;
02319
02320 pNode = pNode->FindNext();
02321 }
02322
02323 View* pView = View::GetCurrent();
02324 Spread* pSpread = pFirstNode->FindParentSpread();
02325
02326 Matrix ViewTrans;
02327 FIXED16 TempScale(1.0);
02328 double Dpi = m_pCapTree->GetRasteriseDPI();
02329
02330
02331
02332 double MPPerPix = 72000.0 / Dpi;
02333
02334 INT32 IntVal = (INT32)floor((double)SpanBounds.lo.x / MPPerPix);
02335 SpanBounds.lo.x = (INT32)floor((double)IntVal * MPPerPix);
02336 IntVal = (INT32)floor((double)SpanBounds.lo.y / MPPerPix);
02337 SpanBounds.lo.y = (INT32)floor((double)IntVal * MPPerPix);
02338 IntVal = (INT32)ceil((double)SpanBounds.hi.x / MPPerPix);
02339 SpanBounds.hi.x = (INT32)ceil((double)IntVal * MPPerPix);
02340 IntVal = (INT32)ceil((double)SpanBounds.hi.y / MPPerPix);
02341 SpanBounds.hi.y = (INT32)ceil((double)IntVal * MPPerPix);
02342
02343 if (SpanBounds.Width() < MPPerPix)
02344 SpanBounds.hi.x = (INT32)ceil((double)SpanBounds.lo.x + MPPerPix);
02345 if (SpanBounds.Height() < MPPerPix)
02346 SpanBounds.hi.y = (INT32)ceil((double)SpanBounds.lo.y + MPPerPix);
02347
02348
02349
02350
02351
02352
02353 GRenderBitmap MaskBitmap(SpanBounds, ViewTrans, TempScale, 32, Dpi);
02354 if (bBackground && bAlpha)
02355 {
02356 MaskBitmap.m_DoCompression = TRUE;
02357 MaskBitmap.AttachDevice(pView, NULL, pSpread);
02358
02359 if (MaskBitmap.StartRender())
02360 {
02361
02362 MaskBitmap.SaveContext();
02363
02364
02365 QualityAttribute *pQualAttr = new QualityAttribute();
02366 pQualAttr->QualityValue.SetQuality(QUALITY_MAX);
02367 MaskBitmap.SetQuality(pQualAttr, TRUE);
02368
02369 XPFSpanRenderCallback MaskCallback(pFirstNode, pLastNode, FALSE);
02370 MaskBitmap.RenderTree(pSpread, FALSE, FALSE, &MaskCallback);
02371
02372
02373 MaskBitmap.RestoreContext();
02374
02375
02376 MaskBitmap.StopRender();
02377 }
02378 }
02379
02380 GRenderBitmap BitmapRR(SpanBounds, ViewTrans, TempScale, 32, Dpi);
02381 if (!bBackground)
02382 BitmapRR.m_DoCompression = TRUE;
02383 BitmapRR.SetForceMixTransparency(bForceMix);
02384 BitmapRR.SetUsingSmoothedBitmaps(TRUE);
02385 BitmapRR.AttachDevice(pView, NULL, pSpread);
02386
02387
02388 if (BitmapRR.StartRender())
02389 {
02390
02391 BitmapRR.SaveContext();
02392
02393 if (bBackground)
02394 {
02395
02396 DocRect DrawRect = SpanBounds;
02397
02398 DrawRect.Inflate( (INT32)(2*72000.0/Dpi + 0.5) );
02399
02400 BitmapRR.SaveContext();
02401 DocColour White(255,255,255);
02402 BitmapRR.SetFillColour(White);
02403 BitmapRR.DrawRect(&DrawRect);
02404 BitmapRR.RestoreContext();
02405 }
02406
02407
02408 QualityAttribute *pQualAttr = new QualityAttribute();
02409 pQualAttr->QualityValue.SetQuality(QUALITY_MAX);
02410 BitmapRR.SetQuality(pQualAttr, TRUE);
02411
02412
02413 TRACEUSER("Gerry", _T("Rendering nodes from 0x%08x to 0x%08x%s\n"), pFirstNode, pLastNode, bBackground ? _T(" with background") : _T(""));
02414 XPFSpanRenderCallback SpanCallback(pFirstNode, pLastNode, bBackground);
02415 BitmapRR.RenderTree(pSpread, FALSE, FALSE, &SpanCallback);
02416
02417
02418 BitmapRR.RestoreContext();
02419
02420
02421 BitmapRR.StopRender();
02422
02423
02424 if (pSingleLayer)
02425 pSingleLayer->SetVisible(bOldLayerVisibility);
02426 }
02427 else
02428 {
02429 ERROR2(NULL, "StartRender failed in RenderNodesToBitmap");
02430 }
02431
02432
02433 OILBitmap* pFullBitmap = BitmapRR.ExtractBitmap();
02434 String_256 BmpName(m_pFilter->GetNewBitmapName());
02435 pFullBitmap->SetName(BmpName);
02436
02437 if (bBackground && bAlpha)
02438 {
02439
02440 OILBitmap* pMaskBitmap = MaskBitmap.ExtractBitmap();
02441 pFullBitmap->CopyFullyTransparentFrom(pMaskBitmap);
02442
02443
02444
02445 KernelBitmap* pTempBmp = KernelBitmap::MakeKernelBitmap(pMaskBitmap);
02446 delete pTempBmp;
02447 }
02448
02449 KernelBitmap* pRealBmp = KernelBitmap::MakeKernelBitmap(pFullBitmap);
02450
02451
02452 if (pSingleBitmap && pSingleBitmap->GetBitmap())
02453 {
02454 pRealBmp->SetAsLossy(pSingleBitmap->GetBitmap()->IsLossy());
02455 }
02456
02457
02458
02459 BitmapList* pBmpList = NULL;
02460 Document* pCurDoc = Document::GetCurrent();
02461 if (pCurDoc)
02462 pBmpList = pCurDoc->GetBitmapList();
02463
02464
02465 pRealBmp->Attach(pBmpList);
02466
02467
02468 NodeBitmap* pNodeBmp = new NodeBitmap();
02469 ERROR2IF(!pNodeBmp, NULL, "Failed to create NodeBitmap");
02470
02471 pNodeBmp->SetUpPath();
02472 pNodeBmp->CreateShape(SpanBounds);
02473 pNodeBmp->BitmapRef.Attach(pRealBmp);
02474 pNodeBmp->ApplyDefaultBitmapAttrs(NULL);
02475
02476
02477 if (TransToApply != TT_NoTranspType && TransToApply != TT_Mix)
02478 {
02479 AttrFlatTranspFill* pTrans = new AttrFlatTranspFill(pNodeBmp, FIRSTCHILD);
02480 if (pTrans)
02481 {
02482 pTrans->SetTranspType(TransToApply);
02483 UINT32 TransVal = 0;
02484 pTrans->SetStartTransp(&TransVal);
02485 }
02486 }
02487
02488 if (pSingleSpread)
02489 {
02490
02491 Spread* pNewSpread = (Spread*)(pSingleSpread->PublicCopy());
02492 ERROR2IF(!pNewSpread, NULL, "Failed to create Spread");
02493
02494 Layer* pNewLayer = new Layer(pNewSpread, FIRSTCHILD, String_256("Layer 1"));
02495 ERROR2IF(!pNewLayer, NULL, "Failed to create Layer");
02496
02497
02498 pNodeBmp->AttachNode(pNewLayer, FIRSTCHILD);
02499
02500
02501 return(pNewSpread);
02502 }
02503
02504 if (pSingleLayer)
02505 {
02506
02507 Layer* pNewLayer = (Layer*)(pSingleLayer->PublicCopy());
02508 ERROR2IF(!pNewLayer, NULL, "Failed to create Layer");
02509
02510
02511 pNodeBmp->AttachNode(pNewLayer, FIRSTCHILD);
02512
02513
02514 return(pNewLayer);
02515 }
02516
02517
02518 return(pNodeBmp);
02519 }
02520
02521
02522
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538 KernelBitmap* XPFRenderCallback::RenderFillToBitmap(Node* pNode, DocRect& BoundsRect)
02539 {
02540 View* pView = View::GetCurrent();
02541 Spread* pSpread = pNode->FindParentSpread();
02542
02543 Matrix ViewTrans;
02544 FIXED16 TempScale(1.0);
02545 double Dpi = m_pCapTree->GetRasteriseDPI();
02546
02547
02548 double MPPerPix = 72000.0 / Dpi;
02549 if (BoundsRect.Width() < MPPerPix)
02550 BoundsRect.hi.x = BoundsRect.lo.x + (INT32)(MPPerPix + 0.5);
02551 if (BoundsRect.Height() < MPPerPix)
02552 BoundsRect.hi.y = BoundsRect.lo.y + (INT32)(MPPerPix + 0.5);
02553
02554 GRenderBitmap BitmapRR(BoundsRect, ViewTrans, TempScale, 32, Dpi);
02555 BitmapRR.m_DoCompression = TRUE;
02556 BitmapRR.AttachDevice(pView, NULL, pSpread);
02557
02558 TRACEUSER( "Gerry", _T("Rendering fill as bitmap (%d, %d)\n"), (INT32)((double)BoundsRect.Width() / MPPerPix), (INT32)((double)BoundsRect.Height() / MPPerPix));
02559
02560
02561 if (!BitmapRR.StartRender())
02562 {
02563 ERROR2(NULL, "StartRender failed in RenderFillToBitmap");
02564 }
02565
02566 BitmapRR.SaveContext();
02567
02568
02569 QualityAttribute *pQualAttr = new QualityAttribute();
02570 pQualAttr->QualityValue.SetQuality(QUALITY_MAX);
02571 BitmapRR.SetQuality(pQualAttr, TRUE);
02572
02573 NodeAttribute* pAttr;
02574 pAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrFillGeometry));
02575 if (pAttr)
02576 pAttr->Render(&BitmapRR);
02577 pAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrFillMapping));
02578 if (pAttr)
02579 pAttr->Render(&BitmapRR);
02580 pAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrFillEffect));
02581 if (pAttr)
02582 pAttr->Render(&BitmapRR);
02583
02584 BitmapRR.SetLineColour(COLOUR_NONE);
02585
02586 Path RectPath;
02587 if (RectPath.Initialise())
02588 {
02589
02590 RectPath.InsertMoveTo(BoundsRect.lo);
02591 RectPath.InsertLineTo(DocCoord(BoundsRect.hi.x, BoundsRect.lo.y));
02592 RectPath.InsertLineTo(BoundsRect.hi);
02593 RectPath.InsertLineTo(DocCoord(BoundsRect.lo.x, BoundsRect.hi.y));
02594 RectPath.InsertLineTo(BoundsRect.lo);
02595
02596
02597 RectPath.CloseSubPath();
02598 RectPath.IsFilled = TRUE;
02599 RectPath.IsStroked = FALSE;
02600 BitmapRR.DrawPath(&RectPath);
02601 }
02602 else
02603 {
02604 pNode->Render(&BitmapRR);
02605 }
02606
02607 BitmapRR.RestoreContext();
02608
02609
02610 BitmapRR.StopRender();
02611
02612 OILBitmap* pFullBitmap = BitmapRR.ExtractBitmap();
02613 String_256 BmpName = m_pFilter->GetNewBitmapName();
02614 pFullBitmap->SetName(BmpName);
02615 KernelBitmap* pRealBmp = KernelBitmap::MakeKernelBitmap(pFullBitmap);
02616
02617
02618
02619 BitmapList* pBmpList = NULL;
02620 Document* pCurDoc = Document::GetCurrent();
02621 if (pCurDoc)
02622 pBmpList = pCurDoc->GetBitmapList();
02623
02624
02625 pRealBmp->Attach(pBmpList);
02626
02627 return(pRealBmp);
02628 }
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649 KernelBitmap* XPFRenderCallback::RenderTransToBitmap(Node* pNode, DocRect& BoundsRect, UINT32* pTransType)
02650 {
02651 View* pView = View::GetCurrent();
02652 Spread* pSpread = pNode->FindParentSpread();
02653
02654 Matrix ViewTrans;
02655 FIXED16 TempScale(1.0);
02656 double Dpi = m_pCapTree->GetRasteriseDPI();
02657
02658
02659 double MPPerPix = 72000.0 / Dpi;
02660 if (BoundsRect.Width() < MPPerPix)
02661 BoundsRect.hi.x = BoundsRect.lo.x + (INT32)(MPPerPix + 0.5);
02662 if (BoundsRect.Height() < MPPerPix)
02663 BoundsRect.hi.y = BoundsRect.lo.y + (INT32)(MPPerPix + 0.5);
02664
02665 GRenderBitmap BitmapRR(BoundsRect, ViewTrans, TempScale, 32, Dpi);
02666 BitmapRR.AttachDevice(pView, NULL, pSpread);
02667
02668 TRACEUSER( "Gerry", _T("Rendering trans as bitmap (%d, %d)\n"), (INT32)((double)BoundsRect.Width() / MPPerPix), (INT32)((double)BoundsRect.Height() / MPPerPix));
02669
02670
02671 if (!BitmapRR.StartRender())
02672 {
02673 ERROR2(NULL, "StartRender failed in RenderTransToBitmap");
02674 }
02675
02676
02677
02678 DocRect DrawRect = BoundsRect;
02679
02680 DrawRect.Inflate( (INT32)(2*72000.0/Dpi + 0.5) );
02681
02682
02683 BitmapRR.SaveContext();
02684 BitmapRR.SetFillColour(COLOUR_WHITE);
02685 BitmapRR.DrawRect(&DrawRect);
02686
02687
02688 QualityAttribute *pQualAttr = new QualityAttribute();
02689 pQualAttr->QualityValue.SetQuality(QUALITY_MAX);
02690 BitmapRR.SetQuality(pQualAttr, TRUE);
02691
02692 NodeAttribute* pAttr;
02693 pAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrTranspFillGeometry));
02694 if (pAttr)
02695 {
02696
02697
02698
02699 TranspFillAttribute* pVal = (TranspFillAttribute*)pAttr->GetAttributeValue();
02700 if (pTransType)
02701 *pTransType = pVal->GetTranspType();
02702 pVal->SetTranspType(TT_Mix);
02703 pAttr->Render(&BitmapRR);
02704 }
02705 pAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrTranspFillMapping));
02706 if (pAttr)
02707 pAttr->Render(&BitmapRR);
02708
02709 BitmapRR.SetFillColour(COLOUR_BLACK);
02710 BitmapRR.SetLineColour(COLOUR_NONE);
02711
02712 Path RectPath;
02713 if (RectPath.Initialise())
02714 {
02715
02716 RectPath.InsertMoveTo(BoundsRect.lo);
02717 RectPath.InsertLineTo(DocCoord(BoundsRect.hi.x, BoundsRect.lo.y));
02718 RectPath.InsertLineTo(BoundsRect.hi);
02719 RectPath.InsertLineTo(DocCoord(BoundsRect.lo.x, BoundsRect.hi.y));
02720 RectPath.InsertLineTo(BoundsRect.lo);
02721
02722
02723 RectPath.CloseSubPath();
02724 RectPath.IsFilled = TRUE;
02725 RectPath.IsStroked = FALSE;
02726 BitmapRR.DrawPath(&RectPath);
02727 }
02728 else
02729 {
02730 pNode->Render(&BitmapRR);
02731 }
02732
02733 BitmapRR.RestoreContext();
02734
02735
02736 BitmapRR.StopRender();
02737
02738 OILBitmap* pFullBitmap = BitmapRR.ExtractBitmap();
02739 String_256 BmpName = m_pFilter->GetNewBitmapName();
02740 pFullBitmap->SetName(BmpName);
02741 KernelBitmap* pRealBmp = KernelBitmap::MakeKernelBitmap(pFullBitmap);
02742
02743
02744
02745 BitmapList* pBmpList = NULL;
02746 Document* pCurDoc = Document::GetCurrent();
02747 if (pCurDoc)
02748 pBmpList = pCurDoc->GetBitmapList();
02749
02750
02751 pRealBmp->Attach(pBmpList);
02752
02753 return(pRealBmp);
02754 }
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772
02773
02774
02775 KernelBitmap* XPFRenderCallback::RenderFillAndTransToBitmap(Node* pNode, DocRect& BoundsRect)
02776 {
02777 BOOL bBackground = FALSE;
02778 NodeAttribute* pTransAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrTranspFillGeometry));
02779 if (pTransAttr)
02780 {
02781 TranspFillAttribute* pTrans = (TranspFillAttribute*)(pTransAttr->GetAttributeValue());
02782 UINT32 Type = pTrans->GetTranspType();
02783 if (Type != TT_NoTranspType &&
02784 Type != TT_Mix &&
02785 Type != TT_DARKEN &&
02786 Type != TT_LIGHTEN &&
02787 Type != TT_BRIGHTNESS &&
02788 Type != TT_BEVEL)
02789 {
02790 bBackground = TRUE;
02791 }
02792 }
02793
02794 if (!m_pCapTree->GetRasteriseAlpha())
02795 bBackground = TRUE;
02796
02797 View* pView = View::GetCurrent();
02798 Spread* pSpread = pNode->FindParentSpread();
02799
02800 Matrix ViewTrans;
02801 FIXED16 TempScale(1.0);
02802 double Dpi = m_pCapTree->GetRasteriseDPI();
02803
02804
02805 double MPPerPix = 72000.0 / Dpi;
02806 if (BoundsRect.Width() < MPPerPix)
02807 BoundsRect.hi.x = BoundsRect.lo.x + (INT32)(MPPerPix + 0.5);
02808 if (BoundsRect.Height() < MPPerPix)
02809 BoundsRect.hi.y = BoundsRect.lo.y + (INT32)(MPPerPix + 0.5);
02810
02811 GRenderBitmap BitmapRR(BoundsRect, ViewTrans, TempScale, 32, Dpi);
02812 if (!bBackground)
02813 BitmapRR.m_DoCompression = TRUE;
02814 BitmapRR.AttachDevice(pView, NULL, pSpread);
02815
02816 TRACEUSER( "Gerry", _T("Rendering fill and trans as bitmap (%d, %d)\n"), (INT32)((double)BoundsRect.Width() / MPPerPix), (INT32)((double)BoundsRect.Height() / MPPerPix));
02817
02818
02819 if (!BitmapRR.StartRender())
02820 {
02821 ERROR2(NULL, "StartRender failed in RenderFillAndTransToBitmap");
02822 }
02823
02824 if (bBackground)
02825 {
02826
02827
02828 DocRect DrawRect = BoundsRect;
02829
02830 DrawRect.Inflate( (INT32)(2*72000.0/Dpi + 0.5) );
02831
02832
02833 BitmapRR.SaveContext();
02834 BitmapRR.SetFillColour(COLOUR_WHITE);
02835 BitmapRR.DrawRect(&DrawRect);
02836 BitmapRR.RestoreContext();
02837 }
02838
02839 BitmapRR.SaveContext();
02840
02841
02842 QualityAttribute *pQualAttr = new QualityAttribute();
02843 pQualAttr->QualityValue.SetQuality(QUALITY_MAX);
02844 BitmapRR.SetQuality(pQualAttr, TRUE);
02845
02846 if (bBackground)
02847 {
02848
02849
02850
02851 Node* pBackNode = pNode->FindPrevious();
02852 Node* pParent = pNode->FindParent();
02853 while (pBackNode == NULL)
02854 {
02855 if (pParent == NULL)
02856 break;
02857 pBackNode = pParent->FindPrevious();
02858 pParent = pParent->FindParent();
02859 }
02860
02861 if (pBackNode)
02862 {
02863 XPFSpanRenderCallback SpanCallback(pBackNode, pBackNode, TRUE);
02864 BitmapRR.RenderTree(pSpread, FALSE, FALSE, &SpanCallback);
02865 }
02866 }
02867
02868 NodeAttribute* pAttr;
02869 pAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrFillGeometry));
02870 if (pAttr)
02871 pAttr->Render(&BitmapRR);
02872 pAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrFillMapping));
02873 if (pAttr)
02874 pAttr->Render(&BitmapRR);
02875 pAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrFillEffect));
02876 if (pAttr)
02877 pAttr->Render(&BitmapRR);
02878 pAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrTranspFillGeometry));
02879 if (pAttr)
02880 pAttr->Render(&BitmapRR);
02881 pAttr = FindChildAttr(pNode, CC_RUNTIME_CLASS(AttrTranspFillMapping));
02882 if (pAttr)
02883 pAttr->Render(&BitmapRR);
02884
02885 BitmapRR.SetLineColour(COLOUR_NONE);
02886
02887 Path RectPath;
02888 if (RectPath.Initialise())
02889 {
02890
02891 RectPath.InsertMoveTo(BoundsRect.lo);
02892 RectPath.InsertLineTo(DocCoord(BoundsRect.hi.x, BoundsRect.lo.y));
02893 RectPath.InsertLineTo(BoundsRect.hi);
02894 RectPath.InsertLineTo(DocCoord(BoundsRect.lo.x, BoundsRect.hi.y));
02895 RectPath.InsertLineTo(BoundsRect.lo);
02896
02897
02898 RectPath.CloseSubPath();
02899 RectPath.IsFilled = TRUE;
02900 RectPath.IsStroked = FALSE;
02901 BitmapRR.DrawPath(&RectPath);
02902 }
02903 else
02904 {
02905 pNode->Render(&BitmapRR);
02906 }
02907
02908 BitmapRR.RestoreContext();
02909
02910
02911 BitmapRR.StopRender();
02912
02913 OILBitmap* pFullBitmap = BitmapRR.ExtractBitmap();
02914 String_256 BmpName = m_pFilter->GetNewBitmapName();
02915 pFullBitmap->SetName(BmpName);
02916 KernelBitmap* pRealBmp = KernelBitmap::MakeKernelBitmap(pFullBitmap);
02917
02918
02919
02920 BitmapList* pBmpList = NULL;
02921 Document* pCurDoc = Document::GetCurrent();
02922 if (pCurDoc)
02923 pBmpList = pCurDoc->GetBitmapList();
02924
02925
02926 pRealBmp->Attach(pBmpList);
02927
02928 return(pRealBmp);
02929 }
02930
02931
02932
02933
02934
02935
02936
02937
02938
02939
02940
02941
02942
02943
02944
02945
02946 BOOL XPFSpanRenderCallback::BeforeNode(RenderRegion* pRegion, Node* pNode)
02947 {
02948
02949
02950
02951 BOOL bRender = FALSE;
02952 switch (m_RenderState)
02953 {
02954 case RS_BEFORESPAN:
02955 if (m_bBackground || pNode->IsAnAttribute() || pNode->IsANodeClipView())
02956 {
02957
02958 bRender = TRUE;
02959 }
02960 break;
02961
02962 case RS_INSPAN:
02963 bRender = TRUE;
02964 break;
02965
02966 case RS_AFTERSPAN:
02967
02968 bRender = FALSE;
02969 break;
02970
02971 default:
02972 TRACE( _T("XPFSpanRC# Bad RenderState in BeforeNode\n"));
02973 break;
02974 }
02975
02976
02977 return(bRender);
02978 }
02979
02980
02981
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992
02993
02994
02995
02996
02997
02998 BOOL XPFSpanRenderCallback::BeforeSubtree(RenderRegion* pRegion, Node* pNode, Node** ppNextNode, BOOL bClip, SubtreeRenderState* pState)
02999 {
03000
03001
03002
03003 switch (m_RenderState)
03004 {
03005 case RS_BEFORESPAN:
03006 if (pNode == m_pFirstNode)
03007 {
03008
03009
03010 m_RenderState = RS_INSPAN;
03011 }
03012 else if (!pNode->IsAnAttribute() && !m_bBackground && !pNode->IsNodeInSubtree(m_pFirstNode))
03013 {
03014
03015 *pState = SUBTREE_NORENDER;
03016 return(TRUE);
03017 }
03018 break;
03019
03020 case RS_INSPAN:
03021 break;
03022
03023 case RS_AFTERSPAN:
03024
03025 *pState = SUBTREE_NORENDER;
03026 return(TRUE);
03027 break;
03028
03029 default:
03030 TRACE( _T("XPFSpanRC# Bad RenderState in BeforeSubtree\n"));
03031 break;
03032 }
03033
03034 return(FALSE);
03035 }
03036
03037
03038
03039
03040
03041
03042
03043
03044
03045
03046
03047
03048
03049
03050
03051
03052 BOOL XPFSpanRenderCallback::AfterSubtree(RenderRegion* pRegion, Node* pNode)
03053 {
03054
03055
03056
03057
03058 BOOL bStopRender = FALSE;
03059 switch (m_RenderState)
03060 {
03061 case RS_BEFORESPAN:
03062 if (!m_bBackground && !pNode->IsNodeInSubtree(m_pFirstNode))
03063 {
03064
03065 bStopRender = TRUE;
03066 }
03067 break;
03068
03069 case RS_INSPAN:
03070 if (pNode == m_pLastNode)
03071 {
03072
03073
03074 m_RenderState = RS_AFTERSPAN;
03075 }
03076 break;
03077
03078 case RS_AFTERSPAN:
03079
03080 bStopRender = TRUE;
03081 break;
03082
03083 default:
03084 TRACE( _T("XPFSpanRC# Bad RenderState in AfterSubtree\n"));
03085 break;
03086 }
03087
03088 return(bStopRender);
03089 }
03090
03091
03092
03093 CommonTransInfo::CommonTransInfo()
03094 {
03095 m_bCommonType = TRUE;
03096 m_CommonType = TT_NoTranspType;
03097 }
03098
03099 void CommonTransInfo::UpdateCommonType(UINT32 Type)
03100 {
03101 if (m_bCommonType)
03102 {
03103 if (Type == TT_NoTranspType ||
03104 Type == TT_DARKEN ||
03105 Type == TT_LIGHTEN ||
03106 Type == TT_BRIGHTNESS ||
03107 Type == TT_BEVEL)
03108 {
03109 Type = TT_Mix;
03110 }
03111
03112 if (m_CommonType == TT_NoTranspType)
03113 m_CommonType = Type;
03114 else if (m_CommonType != Type)
03115 m_bCommonType = FALSE;
03116 }
03117 }
03118
03119 UINT32 CommonTransInfo::GetCommonType()
03120 {
03121 return(m_bCommonType ? m_CommonType : TT_NoTranspType);
03122 }
03123
03124
03125
03126
03127
03128
03129
03130
03131
03132
03133
03134
03135
03136 XPFView::~XPFView()
03137 {
03138 delete pVState;
03139 pVState = 0;
03140 }
03141
03142
03143
03144
03145
03146
03147
03148
03149
03150
03151
03152
03153
03154
03155
03156
03157
03158 BOOL XPFView::Init(double DPI)
03159 {
03160
03161 m_DPI = DPI;
03162
03163
03164 PixelWidth = FIXED16(72000.0 / DPI);
03165 PixelHeight = FIXED16(72000.0 / DPI);
03166 ScaledPixelWidth = PixelWidth;
03167 ScaledPixelHeight = PixelHeight;
03168
03169
03170 pVState = new ViewState;
03171 if (pVState == NULL)
03172 return FALSE;
03173
03174
03175 pVState->pView = this;
03176
03177
03178 return TRUE;
03179 }
03180
03181
03182
03183
03184
03185
03186
03187
03188
03189
03190
03191
03192
03193
03194 BOOL XPFView::ViewStateChanged()
03195 {
03196
03197 DocCoord ExtentLo;
03198 DocCoord ExtentHi;
03199
03200
03201 pDoc->GetExtents(&ExtentLo, &ExtentHi, &PhysExtent, this);
03202 SetExtent(ExtentLo, ExtentHi);
03203
03204 return TRUE;
03205 }
03206
03207
03208
03209
03210
03211
03212
03213
03214
03215
03216
03217
03218
03219
03220 void XPFView::SetViewPixelSize()
03221 {
03222
03223 ScaledPixelWidth = PixelWidth / Scale;
03224 ScaledPixelHeight = PixelHeight / Scale;
03225 }
03226
03227
03228
03229
03230
03231
03232
03233
03234
03235
03236
03237
03238
03239
03240
03241
03242
03243 void XPFView::ContinueRenderView(RenderRegion*, Spread*, BOOL, BOOL,
03244 BOOL bForceImmediate)
03245 {
03246 ERROR3("XPFView::ContinueRenderView() should not be called!");
03247 }
03248
03249
03250
03251
03252
03253
03254
03255
03256
03257
03258
03259
03260
03261
03262
03263 CNativeDC *XPFView::GetRenderDC()
03264 {
03265 return NULL;
03266 }
03267
03268
03269
03270
03271
03272
03273
03274
03275
03276
03277
03278
03279
03280
03281
03282 BOOL XPFView::GetForeBackMode()
03283 {
03284
03285 return FALSE;
03286 }
03287
03288
03289
03290
03291
03292
03293
03294
03295
03296
03297
03298
03299
03300
03301
03302
03303
03304 void XPFView::SetForeBackMode(BOOL)
03305 {
03306 ERROR3("XPFView::SetForeBackMode() should not be called!");
03307 }
03308
03309
03310
03311
03312
03313
03314
03315
03316
03317
03318
03319
03320
03321
03322
03323 DocRect XPFView::GetDocViewRect(Spread* pSpread)
03324 {
03325 return(pSpread->GetBoundingRect());
03326 }
03327
03328
03329
03330
03331
03332
03333
03334
03335
03336
03337
03338
03339
03340
03341
03342
03343
03344
03345
03346 void XPFView::SetExtent(DocCoord lolog, DocCoord hilog)
03347 {
03348
03349 pVState->WorkAreaExtent.lo = lolog.ToWork(pDoc, this);
03350 pVState->WorkAreaExtent.hi = hilog.ToWork(pDoc, this);
03351 }
03352
03353
03354
03355
03356
03357
03358
03359
03360
03361
03362
03363
03364
03365
03366
03367 WorkRect XPFView::GetViewRect()
03368 {
03369 WorkRect Empty;
03370 return Empty;
03371 }
03372
03373
03374
03375
03376
03377
03378
03379
03380
03381
03382
03383
03384
03385
03386
03387
03388 double XPFView::GetConvertToEditableShapesDPI()
03389 {
03390 return(m_DPI);
03391 }