os/textandloc/textrendering/textformatting/tbox/FormLinePag.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 #include "OstTraceDefinitions.h"
    23 #ifdef OST_TRACE_COMPILER_IN_USE
    24 #include "FormLinePagTraces.h"
    25 #endif
    26 
    27 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    28 #include "FRMCONST_INTERNAL.H"
    29 #include "FRMCONST_PARTNER.H"
    30 #endif
    31 
    32 TLinePaginator::TLinePaginator():
    33 	iPageList(NULL),
    34 	iDocPos(0),
    35 	iKeepWithPrev(ETrue),
    36 	iPageHeight(0),
    37 	iHeightRem(0),
    38 	iBreakOnPage(EFalse),
    39 	iPrevPageBreak(0),
    40 	iHeightLines(0),
    41 	iFirstLine(ETrue)
    42 	{
    43 	}
    44 
    45 TBool TLinePaginator::AppendLineL(TPageLine aLine)
    46     //
    47 	{
    48 	TBool pageBreak=EFalse;
    49 
    50 	if(aLine.iStartNewPage && !iFirstLine)	  
    51 		{
    52 		SetPotentialBreakPoint(aLine.iDocPos);
    53 		InsertPageBreakL();
    54 		pageBreak=ETrue;
    55 		}
    56 	else
    57 		{ 
    58 		if (!iKeepWithPrev)
    59 			SetPotentialBreakPoint(aLine.iDocPos);
    60 		if (iHeightRem<iHeightLines+aLine.iLineHeight /*&& !iFirstLine*/)
    61 			{
    62 			pageBreak=ETrue;
    63 			//__ASSERT_DEBUG(!iFirstLine || !iBreakOnPage,Panic());		//###
    64 			if (iBreakOnPage)
    65 				{
    66 				InsertPageBreakL();
    67 				if (aLine.iLineHeight > iHeightRem)
    68 					{
    69 					if (iHeightLines!=0)
    70 						{
    71 						SetPotentialBreakPoint(aLine.iDocPos);
    72 						InsertPageBreakL();
    73 						}
    74 					CheckTallLineL(aLine);
    75 					}
    76 				}
    77 			else 
    78 				{
    79 				if (!iFirstLine)
    80 					{
    81 					SetPotentialBreakPoint(aLine.iDocPos);
    82 					InsertPageBreakL();
    83 					}
    84 				CheckTallLineL(aLine);		//This picks up tall lines at the start of the document the above one picks up the rest
    85 				}
    86 			}
    87 		}
    88 	
    89 	iFirstLine=EFalse;
    90 	iHeightLines+=aLine.iLineHeight;
    91 	iKeepWithPrev=aLine.iKeepWithNext;
    92 	return pageBreak;
    93 	}
    94 
    95 void TLinePaginator::InsertPageBreakL()
    96 	{
    97 	iBreakOnPage=EFalse;
    98 	iHeightRem=iPageHeight;
    99 	iKeepWithPrev=EFalse;
   100 	TInt deltaDocPos=iDocPos-iPrevPageBreak; 
   101 	if (deltaDocPos<=0)
   102 	    {
   103 	    OstTrace0( TRACE_DUMP, TLINEPAGINATOR_INSERTPAGEBREAKL, "EFInvalidNumberCharsOnPage" );
   104 	    }
   105 	__ASSERT_DEBUG(deltaDocPos>0,FormPanic(EFInvalidNumberCharsOnPage));
   106 	iPageList->AppendL(deltaDocPos);
   107 	iPrevPageBreak=iDocPos;
   108 	}
   109 
   110 void TLinePaginator::CheckTallLineL(TPageLine& aLine)
   111 	{
   112 	while (aLine.iLineHeight>iPageHeight)
   113 		{
   114 		aLine.iLineHeight-=iPageHeight;
   115 		iPageList->AppendL(0);
   116 		}
   117 	}
   118 
   119 void TLinePaginator::FlushL(TInt aEndDocPos)
   120 	{
   121 	SetPotentialBreakPoint(aEndDocPos);
   122 	InsertPageBreakL();
   123 	}
   124 
   125 void TLinePaginator::SetPageHeight(TInt aPageHeight)
   126 	{
   127 	iPageHeight=aPageHeight;
   128 	iHeightRem=aPageHeight;
   129 	Reset();
   130 	}
   131 
   132 // It is expected that the array passed in will be an empty one
   133 void TLinePaginator::SetArray(CArrayFix<TInt>* aCharsPerPage)
   134 	{
   135 	iPageList=aCharsPerPage;
   136 	
   137 	// reset if the array is not (for some reason) already cleared.
   138 	if (iPageList->Count() > 0)
   139 		Reset();
   140 	}
   141 
   142 void TLinePaginator::Reset()
   143 	{
   144 	iBreakOnPage=EFalse;
   145 	iKeepWithPrev=ETrue;
   146 	iPrevPageBreak=iDocPos=0;
   147 	iFirstLine=ETrue;
   148 	iHeightRem=iPageHeight;
   149 
   150 	ResetArray();
   151 	}
   152 
   153 void TLinePaginator::ResetArray()
   154 	{
   155 	iPageList->Reset();
   156 	iPageList->Compress();
   157 	}
   158 
   159 void TLinePaginator::SetPotentialBreakPoint(TInt aDocPos)
   160 	{
   161 	iBreakOnPage=ETrue;
   162 	iDocPos=aDocPos;
   163 	iHeightRem-=iHeightLines;
   164 	iHeightLines=0;
   165 	}