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 #include "camtypes.h"
00103 #include "nodetxtl.h"
00104
00105
00106 #include "blobs.h"
00107
00108
00109
00110
00111
00112 #include "nodepath.h"
00113 #include "nodetext.h"
00114 #include "nodetxts.h"
00115
00116
00117
00118
00119
00120
00121 #include "pathproc.h"
00122 #include "fontman.h"
00123 #include "attrmap.h"
00124 #include "cxftext.h"
00125
00126 DECLARE_SOURCE("$Revision: 1535 $")
00127
00128 CC_IMPLEMENT_MEMDUMP(TextLineInfo, CC_CLASS_MEMDUMP)
00129 CC_IMPLEMENT_DYNAMIC(TextLine, BaseTextClass)
00130 CC_IMPLEMENT_DYNAMIC(FormatRegion, RenderRegion)
00131
00132
00133 #define new CAM_DEBUG_NEW
00134
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 TextLineInfo::TextLineInfo()
00147 {
00148 SumCharAdvances = 0;
00149 justification = JLEFT;
00150 LeftMargin = 0;
00151 RightMargin = 0;
00152 ParaLeftMargin = 0;
00153 ParaRightMargin = 0;
00154 Ruler = NULL;
00155 WordWrapping = FALSE;
00156 NumChars = 0;
00157 NumSpaces = 0;
00158 }
00159
00160
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 void TextLine::Init()
00173 {
00174 mLineAscent = 0;
00175 mLineDescent = 0;
00176 mLineSize = 0;
00177
00178 mJustification = JLEFT;
00179 mLineSpacing = 0;
00180 mLineSpaceRatio = 1;
00181 mpRuler = new TxtRuler;
00182
00183 mPosInStory = 0;
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 TextLine::TextLine(): BaseTextClass()
00197 {
00198 Init();
00199 }
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 TextLine::~TextLine()
00211 {
00212 delete mpRuler;
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 TextLine::TextLine(Node* ContextNode,
00236 AttachNodeDirection Direction):BaseTextClass(ContextNode, Direction)
00237 {
00238 Init();
00239 }
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 CopyType TextLine::GetCopyType()
00260 {
00261 return COMPLEXCOPY;
00262 }
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 Node* TextLine::SimpleCopy()
00278 {
00279
00280 TextLine* NodeCopy = new TextLine();
00281
00282 ERROR1IF(NodeCopy == NULL, NULL, _R(IDE_NOMORE_MEMORY));
00283
00284 if (NodeCopy)
00285 CopyNodeContents(NodeCopy);
00286
00287 return NodeCopy;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 INT32 TextLine::ComplexCopy(CopyStage Stage, Range& RangeToCopy, Node** pOutput)
00316 {
00317 TextStory* pTextStory = FindParentStory();
00318 ERROR2IF(pTextStory==NULL,FALSE,"TextLine::ComplexCopy() - pTextStory==NULL");
00319 return pTextStory->BaseComplexCopy(Stage, RangeToCopy, pOutput);
00320 }
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 INT32 TextLine::ComplexHide(UndoableOperation* pOp, Node* pNextNode)
00341 {
00342
00343 BOOL CallComplexHide = TRUE;
00344 TextStory* pThisStory = FindParentStory();
00345 ERROR2IF(pThisStory==NULL,FALSE,"VisibleTextNode::ComplexHide() - pThisStory==NULL");
00346
00347 if (pNextNode)
00348 {
00349 if ( (pNextNode->IsAVisibleTextNode()) ||
00350 (IS_A(pNextNode,TextLine))
00351 )
00352 {
00353 TextStory* pTextStory = FindParentStory();
00354 ERROR2IF(pTextStory==NULL,FALSE,"VisibleTextNode::ComplexHide() - pTextStory==NULL");
00355
00356 if (pThisStory==pTextStory)
00357 CallComplexHide=FALSE;
00358 }
00359 }
00360
00361 if (CallComplexHide)
00362 return pThisStory->BaseComplexHide(pOp);
00363 else
00364 return 1;
00365 }
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 void TextLine::CopyNodeContents(TextLine* NodeCopy)
00380 {
00381
00382 NodeRenderableBounded::CopyNodeContents(NodeCopy);
00383
00384
00385 NodeCopy->mLineAscent = mLineAscent;
00386 NodeCopy->mLineDescent = mLineDescent;
00387 NodeCopy->mLineSize = mLineSize;
00388
00389 NodeCopy->mJustification = mJustification;
00390 NodeCopy->mLineSpacing = mLineSpacing;
00391 NodeCopy->mLineSpaceRatio = mLineSpaceRatio;
00392 NodeCopy->mLeftMargin = mLeftMargin;
00393 NodeCopy->mFirstIndent = mFirstIndent;
00394 NodeCopy->mRightMargin = mRightMargin;
00395 *NodeCopy->mpRuler = *mpRuler;
00396
00397 NodeCopy->mPosInStory = mPosInStory;
00398 }
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 void TextLine::PolyCopyNodeContents(NodeRenderable* pNodeCopy)
00414 {
00415 ENSURE(pNodeCopy, "Trying to copy a node's contents into a NULL node");
00416 ENSURE(IS_A(pNodeCopy, TextLine), "PolyCopyNodeContents given wrong dest node type");
00417
00418 if (IS_A(pNodeCopy, TextLine))
00419 CopyNodeContents((TextLine*)pNodeCopy);
00420 }
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 BOOL TextLine::CreateNodeGroup(NodeGroup** ppNodeGroup, FormatRegion* pFormatRegion, BecomeA* pBecomeA)
00438 {
00439 #ifndef DISABLE_TEXT_RENDERING
00440 ERROR2IF(pFormatRegion==NULL,FALSE,"TextChar::CreateNodeGroup() - pFormatRegion==NULL");
00441 ERROR2IF( pBecomeA==NULL,FALSE,"TextChar::CreateNodeGroup() - pBecomeA==NULL");
00442 ERROR2IF( ppNodeGroup==NULL,FALSE,"TextChar::CreateNodeGroup() - ppNodeGroup==NULL");
00443
00444 pFormatRegion->SaveContext();
00445
00446
00447 Node* pNode=NULL;
00448 TextChar* pTextChar=NULL;
00449
00450
00451
00452 NodeGroup* pLineNodeGroup=NULL;
00453 if (pBecomeA->GetReason()!=BECOMEA_PASSBACK)
00454 {
00455 pLineNodeGroup=new NodeGroup;
00456 if (pLineNodeGroup==NULL)
00457 goto Fail;
00458 }
00459
00460 pNode=FindFirstChild();
00461 while (pNode!=NULL)
00462 {
00463 if (pNode->IsAnAttribute())
00464 {
00465 pNode->Render(pFormatRegion);
00466 if (pBecomeA->GetReason()!=BECOMEA_PASSBACK)
00467 if (!pNode->IsKindOfTextAttribute())
00468 if (pNode->CopyNode(pLineNodeGroup, LASTCHILD)==FALSE)
00469 goto Fail;
00470 }
00471 pNode=pNode->FindNext();
00472 }
00473
00474
00475
00476 pTextChar=(TextChar*)FindFirstChild(CC_RUNTIME_CLASS(TextChar));
00477 while (pTextChar)
00478 {
00479 pFormatRegion->SaveContext();
00480 pTextChar->RenderChildAttrs(pFormatRegion);
00481 NodePath* pCharNodePath=NULL;
00482 if (pTextChar->CreateNodePath(&pCharNodePath,pFormatRegion)==FALSE)
00483 goto Fail;
00484 if (pCharNodePath)
00485 {
00486 if (pBecomeA->GetReason()==BECOMEA_PASSBACK)
00487 {
00488 if (pBecomeA->PassBack(pCharNodePath,pTextChar)==FALSE)
00489 goto Fail;
00490 }
00491 else
00492 {
00493 pCharNodePath->AttachNode(pLineNodeGroup,LASTCHILD);
00494 Node* pNode=pTextChar->FindFirstChild();
00495 while (pNode)
00496 {
00497 if (pNode->IsAnAttribute() && !pNode->IsKindOfTextAttribute())
00498 if (pNode->CopyNode(pCharNodePath, LASTCHILD)==FALSE)
00499 goto Fail;
00500 pNode=pNode->FindNext();
00501 }
00502
00503 pBecomeA->PassBack(pCharNodePath, pTextChar);
00504 }
00505 }
00506 pFormatRegion->RestoreContext();
00507 pTextChar=(TextChar*)(pTextChar->FindNext(CC_RUNTIME_CLASS(TextChar)));
00508 }
00509
00510 *ppNodeGroup=pLineNodeGroup;
00511 pFormatRegion->RestoreContext();
00512 return TRUE;
00513
00514 Fail:
00515 if (pLineNodeGroup)
00516 {
00517 pLineNodeGroup->CascadeDelete();
00518 delete pLineNodeGroup;
00519 }
00520 pFormatRegion->RestoreContext();
00521 #endif
00522 return FALSE;
00523 }
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 TextLine* TextLine::CreateEmptyTextLine(Node* pContextNode, AttachNodeDirection Direction)
00539 {
00540 TextLine* pTextLine = new TextLine();
00541 if (pTextLine==NULL)
00542 return NULL;
00543
00544 EOLNode* pEOL = new EOLNode(pTextLine,FIRSTCHILD);
00545 if (pEOL==NULL)
00546 {
00547 pTextLine->CascadeDelete();
00548 delete pTextLine;
00549 return NULL;
00550 }
00551
00552 if (pContextNode!=NULL)
00553 pTextLine->AttachNode(pContextNode,Direction);
00554
00555 return pTextLine;
00556 }
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569 String TextLine::Describe(BOOL Plural, BOOL Verbose)
00570 {
00571 if (Plural)
00572 return(String(_R(IDS_DESCRIBE_TEXTLINEP)));
00573 else
00574 return(String(_R(IDS_DESCRIBE_TEXTLINES)));
00575 }
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588 DocRect TextLine::GetBlobBoundingRect()
00589 {
00590 #if !defined(EXCLUDE_FROM_RALPH)
00591 DocCoord BlobPos=GetTinyBlobPos();
00592 DocRect BlobBounds;
00593 BlobManager* pBlobMgr=GetApplication()->GetBlobManager();
00594 if (pBlobMgr)
00595 pBlobMgr->GetBlobRect(BlobPos,&BlobBounds);
00596 else
00597 ERROR3("TextLine::GetBlobBoundingRect() - Couldn't find the BlobManager");
00598
00599 IncludeChildrensBoundingRects(&BlobBounds);
00600
00601 return BlobBounds;
00602 #else
00603 return DocRect(0,0,0,0);
00604 #endif
00605 }
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619 DocCoord TextLine::GetTinyBlobPos()
00620 {
00621 #if !defined(EXCLUDE_FROM_RALPH)
00622
00623 DocRect TempRect=GetBoundingRect();
00624 DocCoord BlobPos=DocCoord(TempRect.lo.x,TempRect.hi.y);
00625
00626
00627 AbstractTextChar* pFirstChar=(AbstractTextChar*)FindFirstChild(CC_RUNTIME_CLASS(AbstractTextChar));
00628 if (pFirstChar)
00629 {
00630 if (pFirstChar->GetMetricsRect(&TempRect))
00631 {
00632 BlobPos=DocCoord(TempRect.lo.x,TempRect.hi.y);
00633 Matrix matrix;
00634 if (pFirstChar->GetStoryAndCharMatrix(&matrix))
00635 matrix.transform(&BlobPos);
00636 else
00637 ERROR3("TextLine::GetTinyBlobPos() - GetStoryAndCharMatrix() failed");
00638 }
00639 else
00640 ERROR3("TextLine::GetTinyBlobPos() - GetMetricsRect() failed");
00641 }
00642
00643 return BlobPos;
00644 #else
00645 return DocCoord(0,0);
00646 #endif
00647 }
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659 void TextLine::RenderTinyBlobs(RenderRegion* pRRegion)
00660 {
00661 #if !defined(EXCLUDE_FROM_RALPH)
00662 pRRegion->SetLineColour(COLOUR_NONE);
00663 pRRegion->SetFillColour(COLOUR_UNSELECTEDBLOB);
00664 pRRegion->DrawBlob(GetTinyBlobPos(), BT_UNSELECTED);
00665 #endif
00666 }
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678 void TextLine::RenderObjectBlobs(RenderRegion* pRRegion)
00679 {
00680 #if !defined(EXCLUDE_FROM_RALPH)
00681 RenderTinyBlobs(pRRegion);
00682 #endif
00683 }
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696 UINT32 TextLine::GetNodeSize() const
00697 {
00698 return (sizeof(TextLine));
00699 }
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712 void TextLine::GetDebugDetails(StringBase* Str)
00713 {
00714 NodeRenderableBounded::GetDebugDetails(Str);
00715 }
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728 BOOL TextLine::ReCacheMetrics(FormatRegion* pFormatRegion)
00729 {
00730 TRACEUSER("wuerthne", _T("TextLine::ReCacheMetrics"));
00731 SetJustification( pFormatRegion->GetJustification());
00732 SetLineSpacing( pFormatRegion->GetLineSpacing());
00733 SetLineSpaceRatio(pFormatRegion->GetLineSpaceRatio());
00734
00735 SetParaLeftMargin(pFormatRegion->GetLeftMargin());
00736 SetParaFirstIndent(pFormatRegion->GetFirstIndent());
00737 SetParaRightMargin(pFormatRegion->GetRightMargin());
00738 SetRuler(pFormatRegion->GetRuler());
00739 #if defined(_DEBUG) && 0
00740 String_256 TempStr;
00741 String Str(_T(" "));
00742 for (TxtTabStopIterator It = mpRuler->begin(); It != mpRuler->end(); ++It)
00743 {
00744 switch((*It).GetType())
00745 {
00746 case LeftTab:
00747 TempStr._MakeMsg( TEXT("L(#1%ld)"), (*It).GetPosition());
00748 Str += TempStr;
00749 break;
00750 case RightTab:
00751 TempStr._MakeMsg( TEXT("R(#1%ld)"), (*It).GetPosition());
00752 Str += TempStr;
00753 break;
00754 case CentreTab:
00755 TempStr._MakeMsg( TEXT("C(#1%ld)"), (*It).GetPosition());
00756 Str += TempStr;
00757 break;
00758 case DecimalTab:
00759 TempStr._MakeMsg( TEXT("D(#1%ld)"), (*It).GetPosition());
00760 Str += TempStr;
00761 break;
00762 }
00763 }
00764 TRACEUSER("wuerthne", _T("ruler at %08x:%s"), mpRuler, (TCHAR*)Str);
00765 #endif
00766 return TRUE;
00767 }
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780 MILLIPOINT TextLine::GetEffectiveLeftMargin()
00781 {
00782
00783
00784
00785 TextLine* pPrevLine = FindPrevLine();
00786 if (pPrevLine==NULL || pPrevLine->FindEOLNode() != NULL)
00787 {
00788
00789 return mFirstIndent;
00790 }
00791 else
00792 {
00793 return mLeftMargin;
00794 }
00795 }
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810 BOOL TextLine::Format(TextStoryInfo* pStoryInfo)
00811 {
00812 ERROR2IF(pStoryInfo==NULL,FALSE,"TextLine::Format() - pStoryInfo == NULL");
00813
00814 TRACEUSER("wuerthne", _T("TextLine::Format"));
00815 MILLIPOINT PhysicalLeftMargin = pStoryInfo->LeftPathIndent;
00816 MILLIPOINT PhysicalRightMargin = pStoryInfo->StoryWidth - pStoryInfo->RightPathIndent;
00817 BOOL WordWrapping = pStoryInfo->WordWrapping;
00818 MILLIPOINT RightMargin = PhysicalRightMargin - mRightMargin;
00819 MILLIPOINT LeftIndent = GetEffectiveLeftMargin();
00820
00821
00822 MILLIPOINT WrapWidth = 0;
00823 if (WordWrapping)
00824 WrapWidth = RightMargin - PhysicalLeftMargin;
00825 if (WrapWidth!=0 && pStoryInfo->WordWrap)
00826 {
00827 if (!this->Wrap(pStoryInfo->pUndoOp, WrapWidth, LeftIndent))
00828 return FALSE;
00829 }
00830 else if (WrapWidth != 0)
00831 {
00832
00833
00834
00835 FindBreakChar(WrapWidth, FALSE, LeftIndent);
00836 }
00837
00838
00839 if (NodeOrDescendantAffected())
00840 {
00841 TextLineInfo LineInfo;
00842 if (ReCalcLineInfo(&LineInfo)==FALSE)
00843 return FALSE;
00844
00845 LineInfo.LeftMargin = PhysicalLeftMargin;
00846 LineInfo.RightMargin = PhysicalRightMargin;
00847 LineInfo.WordWrapping = WordWrapping;
00848 if (PositionCharsInLine(&LineInfo)==FALSE)
00849 return FALSE;
00850 }
00851
00852
00853 MILLIPOINT BaseLine = 0;
00854 MILLIPOINT DescentLine = 0;
00855 if (CalcBaseAndDescentLine(&BaseLine,&DescentLine,pStoryInfo->DescentLine,pStoryInfo->DescentLineValid)==FALSE)
00856 return FALSE;
00857 pStoryInfo->DescentLine = DescentLine;
00858 pStoryInfo->DescentLineValid = TRUE;
00859
00860
00861 if (BaseLine!=GetPosInStory())
00862 {
00863 SetPosInStory(BaseLine);
00864 FlagNodeAndDescendantsAffectedAndParentsHaveDescendantAffected();
00865 }
00866
00867
00868 BOOL ok=TRUE;
00869 if (NodeOrDescendantAffected())
00870 {
00871 if (pStoryInfo->pPath==NULL)
00872 ok = SetCharMatrices(GetPosInStory());
00873 else
00874 ok = FitTextToPath(pStoryInfo,GetPosInStory());
00875 }
00876
00877 return ok;
00878 }
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891 BOOL TextLine::EnsureNextLineOfParagraphHasSameLineLevelAttrs(UndoableOperation* pUndoOp)
00892 {
00893 TRACEUSER("wuerthne", _T("EnsureNextLineOfParagraphHasSameLineLevelAttrs"));
00894
00895 ERROR2IF(FindEOLNode()!=NULL,FALSE,"TextLine::EnsureNextOfParagraphLineHasSameLineLevelAttrs() - there is no next line in the paragraph!");
00896 TextStory* pStory = this->FindParentStory();
00897 ERROR2IF(pStory==NULL,FALSE,"TextLine::EnsureNextOfParagraphLineHasSameLineLevelAttrs() - line has no parent story!");
00898 TextLine* pNextLine = this->FindNextLine();
00899 ERROR2IF(pNextLine==NULL,FALSE,"TextLine::EnsureNextOfParagraphLineHasSameLineLevelAttrs() - last line of story has no EOL!");
00900
00901
00902 BOOL StoryLocalised = FALSE;
00903 AttrTypeSet LLASet;
00904 BOOL ok = this->AddChildLineLevelAttrsToSet(&LLASet);
00905 if (ok) ok = pNextLine->AddChildLineLevelAttrsToSet(&LLASet);
00906 if (!ok) return FALSE;
00907
00908
00909
00910 Node* pNextLineNode = pNextLine->FindFirstChild();
00911 while (pNextLineNode!=NULL)
00912 {
00913 if (pNextLineNode->IsAnAttribute() && ((NodeAttribute*)pNextLineNode)->IsALineLevelAttrib())
00914 {
00915 NodeAttribute* pNextLineLLA = (NodeAttribute*)pNextLineNode;
00916 NodeAttribute* pThisLineLLA = (NodeAttribute*)(this->FindFirstChild(pNextLineLLA->GetAttributeType()));
00917 if (pThisLineLLA==NULL || !((*pNextLineLLA)==(*pThisLineLLA)) )
00918 {
00919 if (!StoryLocalised)
00920 if (!pStory->DoLocaliseCommonAttributes(pUndoOp,FALSE,TRUE,&LLASet))
00921 return FALSE;
00922 StoryLocalised = TRUE;
00923 if (pUndoOp!=NULL)
00924 {
00925 if (!pUndoOp->DoHideNode(pNextLineLLA,FALSE))
00926 return FALSE;
00927 }
00928 else
00929 {
00930 pNextLineLLA->CascadeDelete();
00931 delete pNextLineLLA;
00932 }
00933 }
00934 }
00935 pNextLineNode = pNextLineNode->FindNext();
00936 }
00937
00938
00939
00940
00941 Node* pThisLineNode = this->FindFirstChild();
00942 while (pThisLineNode!=NULL)
00943 {
00944 if (pThisLineNode->IsAnAttribute() && ((NodeAttribute*)pThisLineNode)->IsALineLevelAttrib())
00945 {
00946 NodeAttribute* pThisLineLLA = (NodeAttribute*)pThisLineNode;
00947 NodeAttribute* pNextLineLLA = (NodeAttribute*)(pNextLine->FindFirstChild(pThisLineLLA->GetAttributeType()));
00948
00949 if (pNextLineLLA!=NULL && !((*pNextLineLLA)==(*pThisLineLLA)) )
00950 {
00951 if (!StoryLocalised)
00952 if (!pStory->DoLocaliseCommonAttributes(pUndoOp,FALSE,TRUE,&LLASet))
00953 return FALSE;
00954 StoryLocalised = TRUE;
00955 if (pUndoOp!=NULL)
00956 {
00957 if (!pUndoOp->DoHideNode(pNextLineLLA,FALSE))
00958 return FALSE;
00959 }
00960 else
00961 {
00962 pNextLineLLA->CascadeDelete();
00963 delete pNextLineLLA;
00964 }
00965 pNextLineLLA = NULL;
00966 }
00967
00968 if (pNextLineLLA==NULL)
00969 {
00970 if (!StoryLocalised)
00971 if (!pStory->DoLocaliseCommonAttributes(pUndoOp,FALSE,TRUE,&LLASet))
00972 return FALSE;
00973 StoryLocalised = TRUE;
00974 TRACEUSER("wuerthne", _T("calling SimpleCopy for att %d %d"), IS_A(pThisLineLLA, AttrTxtLineSpace), IS_A(pThisLineLLA, AttrTxtRuler));
00975 NodeAttribute* pNewLLA = (NodeAttribute*)pThisLineLLA->SimpleCopy();
00976 TRACEUSER("wuerthne", _T("node copied %d %d"), IS_A(pNewLLA, AttrTxtLineSpace), IS_A(pNewLLA, AttrTxtRuler));
00977 if (pNewLLA==NULL)
00978 return FALSE;
00979 pNewLLA->AttachNode(pNextLine,FIRSTCHILD,TRUE,FALSE);
00980 if (pUndoOp!=NULL)
00981 {
00982 Action* UndoHideAttrAction;
00983 if (HideNodeAction::Init(pUndoOp,pUndoOp->GetUndoActionList(),pNewLLA,TRUE,&UndoHideAttrAction)==AC_FAIL)
00984 return FALSE;
00985 }
00986 }
00987 }
00988 pThisLineNode = pThisLineNode->FindNext();
00989 }
00990
00991
00992 if (StoryLocalised)
00993 {
00994 if (!pStory->DoFactorOutCommonChildAttributes(pUndoOp,TRUE,&LLASet))
00995 return FALSE;
00996 pNextLine->FlagNodeAndDescendantsModifiedByOpAndParentsHaveDescendantModifiedByOp();
00997 }
00998
00999 return TRUE;
01000 }
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012 TextLine* TextLine::FindFirstLineOfParagraph()
01013 {
01014 TextLine* pLine = this;
01015 while (1)
01016 {
01017 TextLine* pPrevLine = pLine->FindPrevLine();
01018 if (pPrevLine==NULL || pPrevLine->FindEOLNode()!=NULL)
01019 break;
01020 pLine = pPrevLine;
01021 }
01022 return pLine;
01023 }
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035 BOOL TextLine::IsAttrTypeLineLevel(CCRuntimeClass* pAttrType)
01036 {
01037 return pAttrType==CC_RUNTIME_CLASS(AttrTxtJustification)
01038 || pAttrType==CC_RUNTIME_CLASS(AttrTxtLineSpace)
01039 || pAttrType==CC_RUNTIME_CLASS(AttrTxtLeftMargin)
01040 || pAttrType==CC_RUNTIME_CLASS(AttrTxtRightMargin)
01041 || pAttrType==CC_RUNTIME_CLASS(AttrTxtFirstIndent)
01042 || pAttrType==CC_RUNTIME_CLASS(AttrTxtRuler);
01043 }
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056 BOOL TextLine::AddChildLineLevelAttrsToSet(AttrTypeSet* pAttrTypeSet)
01057 {
01058 Node* pNode = FindFirstChild();
01059 while (pNode!=NULL)
01060 {
01061 if (pNode->IsAnAttribute() && ((NodeAttribute*)pNode)->IsALineLevelAttrib())
01062 if (!pAttrTypeSet->AddToSet(((NodeAttribute*)pNode)->GetAttributeType()))
01063 return FALSE;
01064 pNode = pNode->FindNext();
01065 }
01066 return TRUE;
01067 }
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086 BOOL FormatState::FinishTabSection(VisibleTextNode* pLastFormattedNode, BOOL IsLastTabSection)
01087 {
01088
01089
01090 if (ActiveTabType != LeftTab)
01091 {
01092
01093 ((HorizontalTab*)pLastTabVTN)->SetCharWidth(RemainingSpace);
01094 ((HorizontalTab*)pLastTabVTN)->SetCharAdvance(RemainingSpace);
01095 }
01096 if (!SetCharPositions) return TRUE;
01097
01098
01099 VisibleTextNode* pVTN = pLastTabVTN ? pLastTabVTN : pFirstVTN;
01100 MILLIPOINT Pos = AnchorPos;
01101 do
01102 {
01103 ERROR2IF(pVTN == NULL, FALSE, "FinishTabSection - unexpected end of line");
01104 if (Pos + CharPosOffset != pVTN->GetPosInLine())
01105 {
01106 pVTN->SetPosInLine(Pos + CharPosOffset);
01107 pVTN->FlagNodeAndDescendantsAffectedAndParentsHaveDescendantAffected();
01108 }
01109 Pos += pVTN->GetCharAdvance();
01110
01111 if (IsLastTabSection && IS_A(pVTN,TextChar))
01112 Pos += ExtraOnChars;
01113 if (IsLastTabSection && pVTN->IsASpace())
01114 Pos += ExtraOnSpaces;
01115 if (pVTN == pLastFormattedNode) break;
01116 pVTN = pVTN->FindNextVTNInLine();
01117 } while(1);
01118 return TRUE;
01119 }
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133 void FormatState::AdvanceBy(MILLIPOINT CharWidth, BOOL IsADecimalPoint)
01134 {
01135
01136
01137 if (ActiveTabType == CentreTab && RemainingSpace > 0)
01138 {
01139 MILLIPOINT SpaceToLeftUsed = 0;
01140
01141 if (RemainingSpace >= CharWidth / 2)
01142 {
01143
01144 SpaceToLeftUsed = CharWidth / 2;
01145 }
01146 else
01147 {
01148
01149 SpaceToLeftUsed = RemainingSpace;
01150 }
01151
01152 RemainingSpace -= SpaceToLeftUsed;
01153
01154 Width += CharWidth - SpaceToLeftUsed;
01155 }
01156 else if ((ActiveTabType == RightTab || (ActiveTabType == DecimalTab && !DecimalPointFound
01157 && !IsADecimalPoint))
01158 && RemainingSpace > 0)
01159 {
01160 if (RemainingSpace >= CharWidth) RemainingSpace -= CharWidth;
01161 else
01162 {
01163 Width += CharWidth - RemainingSpace;
01164 RemainingSpace = 0;
01165 }
01166 }
01167 else
01168 {
01169
01170
01171
01172
01173
01174
01175
01176
01177 Width += CharWidth;
01178 }
01179 }
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193 BOOL FormatState::IsAvailable(MILLIPOINT CharWidth, BOOL IsATab, BOOL IsADecimalPoint)
01194 {
01195
01196
01197 if (Width + CharWidth < FitWidth) return TRUE;
01198
01199
01200
01201
01202 if (ActiveTabType == LeftTab || IsATab) return FALSE;
01203
01204
01205
01206
01207 MILLIPOINT OldWidth = Width;
01208 MILLIPOINT OldRemainingSpace = RemainingSpace;
01209 AdvanceBy(CharWidth, IsADecimalPoint);
01210 MILLIPOINT NewWidth = Width;
01211 Width = OldWidth;
01212 RemainingSpace = OldRemainingSpace;
01213 return NewWidth < FitWidth;
01214 }
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236 VisibleTextNode* TextLine::FindBreakChar(MILLIPOINT FitWidth, BOOL SetCharPositions,
01237 MILLIPOINT Indent, MILLIPOINT CharPosOffset,
01238 MILLIPOINT ExtraOnChars, MILLIPOINT ExtraOnSpaces)
01239 {
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262 TRACEUSER("wuerthne", _T("FindBreakChar, SetCharPositions = %d"), SetCharPositions);
01263 VisibleTextNode* pBreakChar = NULL;
01264 BOOL CharOnLine = FALSE;
01265 VisibleTextNode* pPrevVTN = NULL;
01266 VisibleTextNode* pVTN = this->FindFirstVTN();
01267
01268
01269 FormatState State(FitWidth, SetCharPositions, pVTN, Indent, CharPosOffset, ExtraOnChars, ExtraOnSpaces);
01270
01271 while(pVTN!=NULL)
01272 {
01273 BOOL IsATab = IS_A(pVTN, HorizontalTab);
01274 BOOL IsADecimalPoint = FALSE;
01275 if (State.ActiveTabType == DecimalTab && pVTN->IsATextChar())
01276 {
01277
01278
01279 IsADecimalPoint = (((TextChar*)pVTN)->GetUnicodeValue() == State.DecimalPointChar);
01280 }
01281 if (IsATab)
01282 {
01283 TxtTabType ThisTabType;
01284 MILLIPOINT ThisTabPos;
01285 MILLIPOINT TabWidth;
01286
01287
01288 State.FinishTabSection(pVTN, FALSE);
01289
01290
01291
01292 WCHAR DecimalPointChar;
01293 TxtRulerAttribute::FindTabStopInRuler(mpRuler, State.Width, &ThisTabType, &ThisTabPos,
01294 &DecimalPointChar);
01295 TabWidth = ThisTabPos - State.Width;
01296 ((HorizontalTab*)pVTN)->SetCharAdvance(TabWidth);
01297 ((HorizontalTab*)pVTN)->SetCharWidth(TabWidth);
01298 State.AnchorPos = State.Width;
01299 if (ThisTabType != LeftTab)
01300 {
01301
01302 State.RemainingSpace = TabWidth;
01303 }
01304 if (ThisTabType == DecimalTab)
01305 {
01306 State.DecimalPointChar = DecimalPointChar;
01307 State.DecimalPointFound = FALSE;
01308 }
01309 State.pLastTabVTN = pVTN;
01310 State.ActiveTabType = ThisTabType;
01311 State.ActiveTabPos = ThisTabPos;
01312
01313 pBreakChar = pPrevVTN;
01314 }
01315 if (!pVTN->IsACaret())
01316 {
01317 if (pVTN->IsAnEOLNode())
01318 {
01319 State.FinishTabSection(pVTN, TRUE);
01320 return pVTN;
01321 }
01322 else if (pVTN->IsASpace())
01323 {
01324 State.AdvanceBy(pVTN->GetCharAdvance(), IsADecimalPoint);
01325 pBreakChar = pVTN;
01326 }
01327 else if (!CharOnLine || State.IsAvailable(pVTN->GetCharWidth(), IsATab, IsADecimalPoint))
01328 {
01329 if (IsATab) State.Width += pVTN->GetCharAdvance();
01330 else State.AdvanceBy(pVTN->GetCharAdvance(), IsADecimalPoint);
01331 if (pVTN->IsAHyphen())
01332 pBreakChar = pVTN;
01333 if (State.ActiveTabType == DecimalTab && !State.DecimalPointFound && IsADecimalPoint)
01334 State.DecimalPointFound = TRUE;
01335 }
01336 else
01337 {
01338
01339 if (pBreakChar==NULL)
01340 pBreakChar = pPrevVTN;
01341 if (pBreakChar) State.FinishTabSection(pBreakChar, TRUE);
01342 return pBreakChar;
01343 }
01344 CharOnLine = TRUE;
01345 }
01346 pPrevVTN = pVTN;
01347 if (SetCharPositions)
01348 {
01349
01350 pVTN = pVTN->FindNextVTNInLine();
01351 if (!pVTN)
01352 {
01353 State.FinishTabSection(pPrevVTN, TRUE);
01354 return NULL;
01355 }
01356 }
01357 else
01358 {
01359 pVTN = pVTN->FindNextVTNInStory();
01360 }
01361 }
01362 ERROR2(FALSE,"FindBreakChar() - story has no final EOL!");
01363 }
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378 BOOL TextLine::Wrap(UndoableOperation* pUndoOp, MILLIPOINT WrapWidth, MILLIPOINT Indent)
01379 {
01380 VisibleTextNode* pBreakChar = this->FindBreakChar(WrapWidth, FALSE, Indent);
01381 if (pBreakChar==NULL)
01382 return FALSE;
01383
01384
01385
01386 TextLine* pBreakLine = pBreakChar->FindParentLine();
01387 ERROR2IF(pBreakLine==NULL,FALSE,"TextLine::Wrap() - break char has no parent line");
01388 if (pBreakLine==this)
01389 {
01390 VisibleTextNode* pAfterBreak = pBreakChar->FindNextVTNInLine();
01391 if (pAfterBreak!=NULL)
01392 if (!pAfterBreak->WrapRestOfLineForward(pUndoOp))
01393 return FALSE;
01394 }
01395 else
01396 {
01397 TextLine* pNextLine = this->FindNextLine();
01398 while (pNextLine!=pBreakLine)
01399 {
01400 ERROR2IF(pNextLine==NULL,FALSE,"TextLine::Wrap() - did not find line with break char!");
01401 VisibleTextNode* pLastVTN = pNextLine->FindLastVTN();
01402 ERROR2IF(pLastVTN==NULL,FALSE,"TextLine::Wrap() - no VTN on line!");
01403 if (!pLastVTN->WrapFromStartOfLineBack(pUndoOp))
01404 return FALSE;
01405 pNextLine = this->FindNextLine();
01406 }
01407 if (!pBreakChar->WrapFromStartOfLineBack(pUndoOp))
01408 return FALSE;
01409 }
01410
01411 return TRUE;
01412 }
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426 BOOL TextLine::ReCalcLineInfo(TextLineInfo* pLineInfo)
01427 {
01428 ERROR2IF(pLineInfo==NULL,FALSE,"TextLine::ReCalcLineInfo() - pLineInfo==NULL");
01429
01430 TRACEUSER("wuerthne", _T("RecalcLineInfo"));
01431
01432 SetLineAscent(0);
01433 SetLineDescent(0);
01434 SetLineSize(0);
01435
01436
01437 MILLIPOINT SumCharAdvances = 0;
01438 INT32 NumChars = 0;
01439 INT32 NumSpaces = 0;
01440 MILLIPOINT SumCharAdvancesToLastNonSpace = 0;
01441 INT32 NumCharsToLastNonSpace = 0;
01442 INT32 NumSpacesToLastNonSpace = 0;
01443
01444
01445 BOOL AbstractTextCharFound = FALSE;
01446 Node* pNode = FindFirstChild();
01447 ERROR3IF(pNode==NULL,"TextLine::ReCalcLineInfo() - line has no children!");
01448 while (pNode!=NULL)
01449 {
01450 if (pNode->IsAnAbstractTextChar())
01451 {
01452 AbstractTextChar* pATC= (AbstractTextChar*)pNode;
01453
01454
01455 if (!pATC->IsAnEOLNode() || !AbstractTextCharFound)
01456 {
01457 UpdateLineAscent( pATC->GetFontAscent());
01458 UpdateLineDescent(pATC->GetFontDescent());
01459 UpdateLineSize( pATC->GetFontSize());
01460 }
01461
01462
01463 if (IS_A(pATC,TextChar))
01464 NumChars += 1;
01465 if (IS_A(pATC, HorizontalTab))
01466 {
01467
01468 TRACEUSER("wuerthne", _T("tab at %08x width=%d"), pATC, pATC->GetCharAdvance());
01469 NumSpaces = 0;
01470 NumChars = 0;
01471 }
01472 if (pATC->IsASpace())
01473 NumSpaces += 1;
01474 else if (!pATC->IsAnEOLNode())
01475 {
01476 NumCharsToLastNonSpace = NumChars;
01477 NumSpacesToLastNonSpace = NumSpaces;
01478 SumCharAdvancesToLastNonSpace = SumCharAdvances + pATC->GetCharWidth();
01479 }
01480 SumCharAdvances += pATC->GetCharAdvance();
01481
01482 AbstractTextCharFound = TRUE;
01483 }
01484 pNode = pNode->FindNext();
01485 }
01486 ERROR2IF(!AbstractTextCharFound,FALSE,"TextLine::ReCalcLineInfo() - line has no AbstractTextChars");
01487
01488
01489 pLineInfo->SumCharAdvances = SumCharAdvancesToLastNonSpace;
01490 pLineInfo->NumChars = NumCharsToLastNonSpace;
01491 pLineInfo->NumSpaces = NumSpacesToLastNonSpace;
01492 pLineInfo->justification = GetJustification();
01493 pLineInfo->ParaLeftMargin = GetEffectiveLeftMargin();
01494 pLineInfo->ParaRightMargin = GetParaRightMargin();
01495 pLineInfo->Ruler = GetRuler();
01496 return TRUE;
01497 }
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511 BOOL TextLine::PositionCharsInLine(TextLineInfo* pLineInfo)
01512 {
01513 ERROR2IF(pLineInfo==NULL,FALSE,"TextLine::PositionCharsInLine() - pLineInfo==NULL");
01514
01515
01516 MILLIPOINT PhysicalLeftMargin = pLineInfo->LeftMargin;
01517 MILLIPOINT ParagraphLeftMargin = pLineInfo->ParaLeftMargin;
01518 MILLIPOINT LeftMargin = PhysicalLeftMargin + ParagraphLeftMargin;
01519
01520 MILLIPOINT PhysicalRightMargin = pLineInfo->RightMargin;
01521 MILLIPOINT ParagraphRightMargin = pLineInfo->ParaRightMargin;
01522 MILLIPOINT RightMargin = PhysicalRightMargin - ParagraphRightMargin;
01523
01524 MILLIPOINT SumCharAdvances = pLineInfo->SumCharAdvances;
01525 BOOL WordWrapping = pLineInfo->WordWrapping;
01526 MILLIPOINT JustifyWidth = RightMargin - LeftMargin;
01527
01528 TRACEUSER("wuerthne", _T("PositionCharsInLine, Sum=%d, JWidth=%d"), SumCharAdvances, JustifyWidth);
01529
01530
01531
01532 Justification justification = pLineInfo->justification;
01533 if (WordWrapping && justification==JFULL && SumCharAdvances < JustifyWidth && FindEOLNode()!=NULL)
01534 justification = JLEFT;
01535
01536
01537 MILLIPOINT CharPosOffset = PhysicalLeftMargin;
01538 MILLIPOINT ExtraOnSpaces = 0;
01539 MILLIPOINT ExtraOnChars = 0;
01540 switch (justification)
01541 {
01542
01543
01544 case JRIGHT:
01545 CharPosOffset = RightMargin - SumCharAdvances - ParagraphLeftMargin;
01546 break;
01547 case JCENTRE:
01548 CharPosOffset = (LeftMargin + RightMargin - SumCharAdvances)/2 - ParagraphLeftMargin;
01549 break;
01550 case JFULL:
01551 if (JustifyWidth!=0)
01552 {
01553
01554
01555
01556 INT32 gap = JustifyWidth - SumCharAdvances;
01557 INT32 NumChars = pLineInfo->NumChars;
01558 INT32 NumSpaces = pLineInfo->NumSpaces;
01559 if (gap>0)
01560 {
01561 if (NumSpaces>0)
01562 ExtraOnSpaces = gap/NumSpaces;
01563 else
01564 if (WordWrapping && NumChars>1)
01565 ExtraOnChars = gap/(NumChars-1);
01566 }
01567 else
01568 if (pLineInfo->NumChars>1)
01569 ExtraOnChars = gap/(NumChars-1);
01570 }
01571 break;
01572 default:
01573 break;
01574 }
01575
01576
01577 TRACEUSER("wuerthne", _T("calling FindBreakChar, Indent=%d, Offset=%d, ExtraC=%d, ExtraS=%d"),
01578 ParagraphLeftMargin, CharPosOffset, ExtraOnChars, ExtraOnSpaces);
01579 FindBreakChar(INT32_MAX, TRUE, ParagraphLeftMargin, CharPosOffset, ExtraOnChars, ExtraOnSpaces);
01580 return TRUE;
01581 }
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600 BOOL TextLine::CalcBaseAndDescentLine(MILLIPOINT* pBaseLine, MILLIPOINT* pDescentLine,
01601 MILLIPOINT LastDescentLine, BOOL LastDescentLineValid)
01602 {
01603
01604 MILLIPOINT LineAscent = GetLineAscent();
01605 MILLIPOINT LineDescent = GetLineDescent();
01606 MILLIPOINT LineHeight = LineAscent-LineDescent;
01607 MILLIPOINT LineSpacing = GetLineSpacing();
01608
01609 MILLIPOINT BaseLine = 0;
01610 MILLIPOINT DescentLine = 0;
01611 if (LineSpacing!=0)
01612 {
01613 MILLIPOINT OffsetFromDescentLineToBaseLine = MulDiv(LineSpacing, -LineDescent, LineHeight);
01614 if (LastDescentLineValid)
01615 {
01616 DescentLine = LastDescentLine - LineSpacing;
01617 BaseLine = DescentLine + OffsetFromDescentLineToBaseLine;
01618 }
01619 else
01620 DescentLine = BaseLine - OffsetFromDescentLineToBaseLine;
01621 }
01622 else
01623 {
01624 FIXED16 LineSpaceRatio = GetLineSpaceRatio();
01625 MILLIPOINT AbsolutLineSpacing = MILLIPOINT( XLONG(LineHeight) * LineSpaceRatio );
01626 MILLIPOINT OffsetFromLastDescentLineToBaseLine = LineAscent;
01627 if (LineSpaceRatio<1)
01628 OffsetFromLastDescentLineToBaseLine = XLONG(LineAscent) * LineSpaceRatio;
01629
01630 if (LastDescentLineValid)
01631 {
01632 BaseLine = LastDescentLine - OffsetFromLastDescentLineToBaseLine;
01633 DescentLine = LastDescentLine - AbsolutLineSpacing;
01634 }
01635 else
01636 DescentLine = BaseLine + OffsetFromLastDescentLineToBaseLine - AbsolutLineSpacing;
01637 }
01638
01639
01640 *pDescentLine = DescentLine;
01641 *pBaseLine = BaseLine;
01642
01643 return TRUE;
01644 }
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657 BOOL TextLine::SetCharMatrices(MILLIPOINT LinePos)
01658 {
01659 Node* pNode=FindFirstChild();
01660 while (pNode!=NULL)
01661 {
01662 if (pNode->IsAVisibleTextNode())
01663 {
01664 VisibleTextNode* pVTN=(VisibleTextNode*)pNode;
01665 if (pVTN->Affected())
01666 pVTN->SetMatrix( Matrix( pVTN->GetPosInLine(), LinePos+pVTN->GetBaseLineShift() ) );
01667 }
01668 pNode=pNode->FindNext();
01669 }
01670 return TRUE;
01671 }
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686 BOOL TextLine::FitTextToPath(TextStoryInfo* pStoryInfo, MILLIPOINT LinePos)
01687 {
01688 ERROR2IF(pStoryInfo==NULL,FALSE,"TextLine::FitTextToPath() - pStoryInfo==NULL");
01689 TextStory* pTextStory = FindParentStory();
01690 ERROR2IF(pTextStory==NULL,FALSE,"TextLine::FitTextToPath() - pTextStory==NULL");
01691
01692
01693 FIXED16 scale = pTextStory->GetCharsScale();
01694 FIXED16 xscale = (scale<0 ? -scale : scale) * pTextStory->GetCharsAspect();
01695 FIXED16 shear = scale * tan(pTextStory->GetCharsShear().MakeDouble());
01696
01697
01698
01699 LinePos = XLONG(LinePos) * scale;
01700 MILLIPOINT LinePosX = (MILLIPOINT)(LinePos * pStoryInfo->UnitDirectionVectorX + 0.5);
01701 MILLIPOINT LinePosY = (MILLIPOINT)(LinePos * pStoryInfo->UnitDirectionVectorY + 0.5);
01702
01703
01704
01705 double TangentAtDist=0;
01706 double* pTangentAtDist=NULL;
01707 if (pTextStory->IsTextOnPathTangential())
01708 pTangentAtDist=&TangentAtDist;
01709
01710
01711 BOOL Found=FALSE;
01712 DocCoord CoordAtDist(0,0);
01713 Matrix VTNMatrix(0,0);
01714 ProcessPathDistance PathDistanceProcess(64);
01715
01716 Node* pNode=FindFirstChild();
01717 while (pNode)
01718 {
01719 if (pNode->IsAVisibleTextNode())
01720 {
01721 VisibleTextNode* pVTN=(VisibleTextNode*)pNode;
01722 if (pVTN->Affected())
01723 {
01724
01725 MILLIPOINT CharWidthBy2 = XLONG(pVTN->GetCharWidth()/2) * xscale;
01726 MILLIPOINT Dist=XLONG(pVTN->GetPosInLine()) * xscale + CharWidthBy2;
01727
01728 if (pStoryInfo->PathClosed)
01729 {
01730 Dist = Dist % pStoryInfo->PathLength;
01731 if (Dist<0)
01732 Dist += pStoryInfo->PathLength;
01733 }
01734
01735
01736 if (PathDistanceProcess.GetCoordAndTangent(&CoordAtDist,pTangentAtDist,&Found,Dist,pStoryInfo->pPath)==FALSE)
01737 return FALSE;
01738
01739
01740 VTNMatrix=Matrix( xscale, 0, shear, scale, 0, XLONG(pVTN->GetBaseLineShift()) * scale );
01741
01742
01743 VTNMatrix*=Matrix(DocCoord(CharWidthBy2,0),TangentAtDist/PI*180);
01744
01745 VTNMatrix.translate(CoordAtDist.x-CharWidthBy2+LinePosX,CoordAtDist.y+LinePosY);
01746 pVTN->SetMatrix(VTNMatrix);
01747 }
01748 }
01749 pNode=pNode->FindNext();
01750 }
01751
01752 return TRUE;
01753 }
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771 VisibleTextNode* TextLine::FindCharAtDistAlongLine(MILLIPOINT Distance, BOOL* LeftHandSide)
01772 {
01773 ERROR2IF(LeftHandSide==NULL,NULL,"TextLine::FindCharAtDistAlongLine() - NULL side pointer");
01774
01775 VisibleTextNode* pVTN = FindFirstVTN();
01776 ERROR2IF(pVTN==NULL,NULL,"TextLine::FindCharAtDistAlongLine() - has no VTN");
01777 while (1)
01778 {
01779 const MILLIPOINT Left = pVTN->GetPosInLine();
01780 const MILLIPOINT Centre = Left+pVTN->GetCharWidth()/2;
01781 const MILLIPOINT Next = Left+pVTN->GetCharAdvance();
01782
01783
01784
01785 if (Distance<=Centre || pVTN->IsAnEOLNode())
01786 {
01787 *LeftHandSide = TRUE;
01788 return pVTN;
01789 }
01790
01791
01792
01793 if (Distance<=Next)
01794 {
01795 *LeftHandSide = FALSE;
01796 return pVTN;
01797 }
01798
01799
01800 VisibleTextNode* pNextVTN = pVTN->FindNextVTNInLine();
01801 if (pNextVTN==NULL)
01802 {
01803 *LeftHandSide = FALSE;
01804 return pVTN;
01805 }
01806 pVTN = pNextVTN;
01807 }
01808 }
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818 CaretNode* TextLine::FindCaret() const
01819 {
01820 return (CaretNode*)FindFirstChild(CC_RUNTIME_CLASS(CaretNode));
01821 }
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833 BOOL TextLine::WholeLineSelected()
01834 {
01835 if (IsSelected()==FALSE)
01836 {
01837 VisibleTextNode* pVTN = FindFirstVTN();
01838 ERROR2IF(pVTN==NULL,FALSE,"TextLine::WholeLineSelected() - line has no VTN!");
01839 while (pVTN!=NULL)
01840 {
01841 if (!pVTN->IsSelected() && !pVTN->IsACaret())
01842 return FALSE;
01843 pVTN = pVTN->FindNextVTNInLine();
01844 }
01845 }
01846 return TRUE;
01847 }
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858 TextLine* TextLine::FindNextLine() const
01859 {
01860 return (TextLine*)FindNext(CC_RUNTIME_CLASS(TextLine));
01861 }
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871 TextLine* TextLine::FindPrevLine() const
01872 {
01873 return (TextLine*)FindPrevious(CC_RUNTIME_CLASS(TextLine));
01874 }
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885 VisibleTextNode* TextLine::FindFirstVTN() const
01886 {
01887 return (VisibleTextNode*)FindFirstChild(CC_RUNTIME_CLASS(VisibleTextNode));
01888 }
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899 VisibleTextNode* TextLine::FindLastVTN() const
01900 {
01901 return (VisibleTextNode*)FindLastChild(CC_RUNTIME_CLASS(VisibleTextNode));
01902 }
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912 EOLNode* TextLine::FindEOLNode() const
01913 {
01914 EOLNode* pEOL = (EOLNode*)FindFirstChild(CC_RUNTIME_CLASS(EOLNode));
01915 ERROR3IF(pEOL!=NULL && pEOL->FindNext(CC_RUNTIME_CLASS(EOLNode))!=NULL,
01916 "TextLine::FindEOLNode() - more than one EOLNode on a line!");
01917 return pEOL;
01918 }
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929 MILLIPOINT TextLine::GetLastCharTracking()
01930 {
01931 AbstractTextChar* pATC = (AbstractTextChar*)FindFirstChild(CC_RUNTIME_CLASS(AbstractTextChar));
01932 if (pATC->IsAnEOLNode())
01933 pATC = (AbstractTextChar*)(pATC->FindPrevious(CC_RUNTIME_CLASS(AbstractTextChar)));
01934
01935 if (pATC==NULL)
01936 return 0;
01937
01938 return pATC->GetCharAdvance() - pATC->GetCharWidth();
01939 }
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956 BOOL TextLine::WillLineWrapOnPath(FIXED16 xscale, MILLIPOINT PLength)
01957 {
01958 TextStory* pTextStory = FindParentStory();
01959 ERROR2IF(pTextStory==NULL,FALSE,"TextLine::IsLineWrappedOnPath() - pTextStory==NULL");
01960
01961 BOOL found = FALSE;
01962 Node* pNode=FindLastChild();
01963 while (pNode && !found)
01964 {
01965 if (pNode->IsAVisibleTextNode())
01966 found = TRUE;
01967 else
01968 pNode=pNode->FindPrevious();
01969 }
01970
01971 if (pNode)
01972 {
01973 VisibleTextNode* pVTN=(VisibleTextNode*)pNode;
01974 MILLIPOINT Dist=XLONG(pVTN->GetPosInLine()) * xscale;
01975 if (Dist>PLength)
01976 return TRUE;
01977 }
01978 return FALSE;
01979 }
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994 BOOL TextLine::WritePreChildrenWeb(BaseCamelotFilter *pFilter)
01995 {
01996 #ifdef DO_EXPORT
01997 return CXaraFileTxtLine::WritePreChildrenWeb(pFilter, this);
01998 #else
01999 return FALSE;
02000 #endif
02001 }
02002
02003 BOOL TextLine::WritePreChildrenNative(BaseCamelotFilter *pFilter)
02004 {
02005 #ifdef DO_EXPORT
02006 return CXaraFileTxtLine::WritePreChildrenNative(pFilter, this);
02007 #else
02008 return FALSE;
02009 #endif
02010 }
02011
02012
02013
02014 BOOL TextLine::WriteBeginChildRecordsWeb(BaseCamelotFilter* pFilter)
02015 {
02016 #ifdef DO_EXPORT
02017 return CXaraFileTxtLine::WriteBeginChildRecordsWeb(pFilter, this);
02018 #else
02019 return FALSE;
02020 #endif
02021 }
02022
02023 BOOL TextLine::WriteBeginChildRecordsNative(BaseCamelotFilter* pFilter)
02024 {
02025 #ifdef DO_EXPORT
02026 return CXaraFileTxtLine::WriteBeginChildRecordsNative(pFilter, this);
02027 #else
02028 return FALSE;
02029 #endif
02030 }
02031
02032 BOOL TextLine::WriteEndChildRecordsWeb(BaseCamelotFilter* pFilter)
02033 {
02034 #ifdef DO_EXPORT
02035 return CXaraFileTxtLine::WriteEndChildRecordsWeb(pFilter, this);
02036 #else
02037 return FALSE;
02038 #endif
02039 }
02040
02041 BOOL TextLine::WriteEndChildRecordsNative(BaseCamelotFilter* pFilter)
02042 {
02043 #ifdef DO_EXPORT
02044 return CXaraFileTxtLine::WriteEndChildRecordsNative(pFilter, this);
02045 #else
02046 return FALSE;
02047 #endif
02048 }
02049
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062 FormatRegion::FormatRegion() : RenderRegion()
02063 {
02064 CurrentClipRect = DocRect(0,0,0,0);
02065 ScaledPixelWidth = 1;
02066 }
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077 FormatRegion::~FormatRegion()
02078 {
02079 }
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093
02094 BOOL FormatRegion::Init(NodeRenderableInk* pFirstNode)
02095 {
02096 m_pFormatDC = std::auto_ptr<wxDC>( new wxMemoryDC );
02097 if( NULL == m_pFormatDC.get() )
02098 ERROR2(FALSE,"FormatRegion::Init() - CreateCompatibleDC() failed");
02099
02100 RenderView = DocView::GetSelected();
02101
02102
02103
02104
02105
02106 if (RenderView == NULL)
02107 {
02108 RenderView = View::GetCurrent();
02109 if (RenderView == NULL)
02110 {
02111 ERROR3("No view!! Can't format text without a view");
02112 return FALSE;
02113 }
02114
02115
02116 }
02117
02118
02119 StartRender();
02120
02121
02122 if (pFirstNode==NULL)
02123 return TRUE;
02124
02125 CCAttrMap *pAttribMap = new CCAttrMap(30);
02126 if (pAttribMap == NULL) return FALSE;
02127
02128 if (!pFirstNode->FindAppliedAttributes(pAttribMap))
02129 {
02130 delete pAttribMap;
02131 return FALSE;
02132 }
02133
02134 CCAttrMap::iterator pos = pAttribMap->GetStartPosition();
02135 CCAttrMap::iterator end = pAttribMap->GetEndPosition();
02136 while( pos != end )
02137 {
02138 CCRuntimeClass *pKey;
02139 void *pVal;
02140 pAttribMap->GetNextAssoc(pos, pKey, pVal);
02141
02142 ((NodeAttribute*) pVal)->Render(this);
02143 }
02144
02145 delete pAttribMap;
02146
02147 return TRUE;
02148 }
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162 BOOL FormatRegion::GetCharMetrics(CharMetrics* pCharMetrics, WCHAR ch)
02163 {
02164 ERROR2IF(pCharMetrics==NULL, FALSE, "FormatRegion::GetCharMetrics() - pCharMetrics==NULL");
02165
02166
02167 wxDC *pDC = m_pFormatDC.get();
02168 CharDescription FontDesc( FONTEMCHAR, RR_TXTFONTTYPEFACE(), RR_TXTBOLD(), RR_TXTITALIC() );
02169 if( FONTMANAGER->GetCharMetrics( pDC, ch, FontDesc, pCharMetrics ) == FALSE )
02170 return FALSE;
02171
02172
02173
02174
02175 TxtScriptAttribute* pScriptAttr=RR_TXTSCRIPT();
02176 ERROR2IF(pScriptAttr==NULL,FALSE,"RenderRegion::GetCharAttributeMatrix() - pScriptAttr==NULL");
02177 double ScaleY = (double)RR_TXTFONTSIZE() / TextManager::GetDefaultHeight();
02178 double ScaleX = ScaleY * RR_TXTASPECTRATIO().MakeDouble() * pScriptAttr->Size.MakeDouble();
02179 pCharMetrics->Scale(ScaleX,ScaleY);
02180
02181 return TRUE;
02182 }
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196 MILLIPOINT FormatRegion::GetCharsKerning(WCHAR chLeft, WCHAR chRight)
02197 {
02198
02199 wxDC *pDC = m_pFormatDC.get();
02200 CharDescription FontDesc(FONTEMCHAR, RR_TXTFONTTYPEFACE(), RR_TXTBOLD(), RR_TXTITALIC());
02201 MILLIPOINT kern = FONTMANAGER->GetCharsKerning( pDC, chLeft, chRight, FontDesc );
02202
02203
02204
02205
02206 TxtScriptAttribute* pScriptAttr=RR_TXTSCRIPT();
02207 ERROR2IF(pScriptAttr==NULL,FALSE,"RenderRegion::GetCharAttributeMatrix() - pScriptAttr==NULL");
02208 double ScaleY = (double)RR_TXTFONTSIZE() / TextManager::GetDefaultHeight();
02209 double ScaleX = ScaleY * RR_TXTASPECTRATIO().MakeDouble() * pScriptAttr->Size.MakeDouble();
02210
02211 if (kern)
02212 kern = (MILLIPOINT)(kern * ScaleX + 0.5);
02213
02214 return kern;
02215 }