textrendering/textformatting/tbox/FormLinePag.cpp
changeset 32 8b9155204a54
parent 0 1fb32624e06b
child 40 91ef7621b7fc
equal deleted inserted replaced
31:b9ad20498fb4 32:8b9155204a54
       
     1 /*
       
     2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "FRMPAGE.H"
       
    20 #include "FRMCONST.H"
       
    21 
       
    22 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    23 #include "FRMCONST_INTERNAL.H"
       
    24 #include "FRMCONST_PARTNER.H"
       
    25 #endif
       
    26 
       
    27 TLinePaginator::TLinePaginator():
       
    28 	iPageList(NULL),
       
    29 	iDocPos(0),
       
    30 	iKeepWithPrev(ETrue),
       
    31 	iPageHeight(0),
       
    32 	iHeightRem(0),
       
    33 	iBreakOnPage(EFalse),
       
    34 	iPrevPageBreak(0),
       
    35 	iHeightLines(0),
       
    36 	iFirstLine(ETrue)
       
    37 	{
       
    38 	}
       
    39 
       
    40 TBool TLinePaginator::AppendLineL(TPageLine aLine)
       
    41     //
       
    42 	{
       
    43 	TBool pageBreak=EFalse;
       
    44 
       
    45 	if(aLine.iStartNewPage && !iFirstLine)	  
       
    46 		{
       
    47 		SetPotentialBreakPoint(aLine.iDocPos);
       
    48 		InsertPageBreakL();
       
    49 		pageBreak=ETrue;
       
    50 		}
       
    51 	else
       
    52 		{ 
       
    53 		if (!iKeepWithPrev)
       
    54 			SetPotentialBreakPoint(aLine.iDocPos);
       
    55 		if (iHeightRem<iHeightLines+aLine.iLineHeight /*&& !iFirstLine*/)
       
    56 			{
       
    57 			pageBreak=ETrue;
       
    58 			//__ASSERT_DEBUG(!iFirstLine || !iBreakOnPage,Panic());		//###
       
    59 			if (iBreakOnPage)
       
    60 				{
       
    61 				InsertPageBreakL();
       
    62 				if (aLine.iLineHeight > iHeightRem)
       
    63 					{
       
    64 					if (iHeightLines!=0)
       
    65 						{
       
    66 						SetPotentialBreakPoint(aLine.iDocPos);
       
    67 						InsertPageBreakL();
       
    68 						}
       
    69 					CheckTallLineL(aLine);
       
    70 					}
       
    71 				}
       
    72 			else 
       
    73 				{
       
    74 				if (!iFirstLine)
       
    75 					{
       
    76 					SetPotentialBreakPoint(aLine.iDocPos);
       
    77 					InsertPageBreakL();
       
    78 					}
       
    79 				CheckTallLineL(aLine);		//This picks up tall lines at the start of the document the above one picks up the rest
       
    80 				}
       
    81 			}
       
    82 		}
       
    83 	
       
    84 	iFirstLine=EFalse;
       
    85 	iHeightLines+=aLine.iLineHeight;
       
    86 	iKeepWithPrev=aLine.iKeepWithNext;
       
    87 	return pageBreak;
       
    88 	}
       
    89 
       
    90 void TLinePaginator::InsertPageBreakL()
       
    91 	{
       
    92 	iBreakOnPage=EFalse;
       
    93 	iHeightRem=iPageHeight;
       
    94 	iKeepWithPrev=EFalse;
       
    95 	TInt deltaDocPos=iDocPos-iPrevPageBreak; 
       
    96 	__ASSERT_DEBUG(deltaDocPos>0,FormPanic(EFInvalidNumberCharsOnPage));
       
    97 	iPageList->AppendL(deltaDocPos);
       
    98 	iPrevPageBreak=iDocPos;
       
    99 	}
       
   100 
       
   101 void TLinePaginator::CheckTallLineL(TPageLine& aLine)
       
   102 	{
       
   103 	while (aLine.iLineHeight>iPageHeight)
       
   104 		{
       
   105 		aLine.iLineHeight-=iPageHeight;
       
   106 		iPageList->AppendL(0);
       
   107 		}
       
   108 	}
       
   109 
       
   110 void TLinePaginator::FlushL(TInt aEndDocPos)
       
   111 	{
       
   112 	SetPotentialBreakPoint(aEndDocPos);
       
   113 	InsertPageBreakL();
       
   114 	}
       
   115 
       
   116 void TLinePaginator::SetPageHeight(TInt aPageHeight)
       
   117 	{
       
   118 	iPageHeight=aPageHeight;
       
   119 	iHeightRem=aPageHeight;
       
   120 	Reset();
       
   121 	}
       
   122 
       
   123 // It is expected that the array passed in will be an empty one
       
   124 void TLinePaginator::SetArray(CArrayFix<TInt>* aCharsPerPage)
       
   125 	{
       
   126 	iPageList=aCharsPerPage;
       
   127 	
       
   128 	// reset if the array is not (for some reason) already cleared.
       
   129 	if (iPageList->Count() > 0)
       
   130 		Reset();
       
   131 	}
       
   132 
       
   133 void TLinePaginator::Reset()
       
   134 	{
       
   135 	iBreakOnPage=EFalse;
       
   136 	iKeepWithPrev=ETrue;
       
   137 	iPrevPageBreak=iDocPos=0;
       
   138 	iFirstLine=ETrue;
       
   139 	iHeightRem=iPageHeight;
       
   140 
       
   141 	ResetArray();
       
   142 	}
       
   143 
       
   144 void TLinePaginator::ResetArray()
       
   145 	{
       
   146 	iPageList->Reset();
       
   147 	iPageList->Compress();
       
   148 	}
       
   149 
       
   150 void TLinePaginator::SetPotentialBreakPoint(TInt aDocPos)
       
   151 	{
       
   152 	iBreakOnPage=ETrue;
       
   153 	iDocPos=aDocPos;
       
   154 	iHeightRem-=iHeightLines;
       
   155 	iHeightLines=0;
       
   156 	}