os/textandloc/textrendering/textformatting/test/src/TCustomWrap.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#ifndef TCUSTOMWRAP_H_
sl@0
    20
sl@0
    21
#include <frmtlay.h>
sl@0
    22
#include <linebreak.h>
sl@0
    23
sl@0
    24
// ------------ TTestCustomWrap ---------
sl@0
    25
sl@0
    26
/**
sl@0
    27
 * A custom wrapping class that allows line breaks anywhere, but allows (Latin)
sl@0
    28
 * commas, full-stops and closing brackets to "wrap-up" to the previous line.
sl@0
    29
 */
sl@0
    30
class TTestCustomWrap : public MFormCustomWrap
sl@0
    31
	{
sl@0
    32
	// All characters are given the same class. It does not matter which it is
sl@0
    33
	// as long as it is not ESpLineBreakClass. Spaces must not be treated
sl@0
    34
	// differently from other characters.
sl@0
    35
	TUint LineBreakClass(TUint /*aCode*/,TUint& aRangeStart,TUint& aRangeEnd) const
sl@0
    36
		{
sl@0
    37
		// All characters have the same class..
sl@0
    38
		aRangeStart = 0;
sl@0
    39
		aRangeEnd = 0x110000;
sl@0
    40
		// ..this class is Ideographic
sl@0
    41
		return MTmCustom::EIdLineBreakClass;
sl@0
    42
		}
sl@0
    43
	TBool LineBreakPossible(TUint /*aPrevClass*/,
sl@0
    44
		TUint /*aNextClass*/, TBool /*aHaveSpaces*/) const
sl@0
    45
		{
sl@0
    46
		// Line breaking allowed between any class of characters.
sl@0
    47
		// In practice they will all be EIdLineBreakClass, because we have
sl@0
    48
		// fixed it so that they will be.
sl@0
    49
		return ETrue;
sl@0
    50
		}
sl@0
    51
	TBool IsHangingCharacter(TUint aChar) const
sl@0
    52
		{
sl@0
    53
		// Allow commas, full stops and closing brackets to hang over the
sl@0
    54
		// margins. In practice, ideographic commas, full-stops and brackets
sl@0
    55
		// should be allowed as well as many other types of closing punctuation.
sl@0
    56
		if (aChar == ',' || aChar == '.' || aChar == ')')
sl@0
    57
			return ETrue;
sl@0
    58
		return EFalse;
sl@0
    59
		}
sl@0
    60
	};
sl@0
    61
	
sl@0
    62
/**
sl@0
    63
 * A custom wrapping class that allows line breaks between alphabetic and 
sl@0
    64
 * break after classes
sl@0
    65
 */	
sl@0
    66
class TTestCustomWrap2 : public MFormCustomWrap
sl@0
    67
	{
sl@0
    68
sl@0
    69
	TBool LineBreakPossible(TUint aPrevClass,
sl@0
    70
		TUint aNextClass, TBool aHaveSpaces) const
sl@0
    71
		{
sl@0
    72
		TBool breakAllowed;
sl@0
    73
		breakAllowed = MFormCustomWrap::LineBreakPossible(aPrevClass,aNextClass,aHaveSpaces);
sl@0
    74
			
sl@0
    75
		if(!breakAllowed)
sl@0
    76
			{
sl@0
    77
			//Specifically allow breaking between alphabetic and break after
sl@0
    78
			//classes (e.g. Tab character)
sl@0
    79
			breakAllowed = ((aPrevClass == MLineBreaker::EAlLineBreakClass) 
sl@0
    80
							&& (aNextClass == MLineBreaker::EBaLineBreakClass));
sl@0
    81
			}
sl@0
    82
		
sl@0
    83
		return breakAllowed;
sl@0
    84
		}
sl@0
    85
sl@0
    86
	};
sl@0
    87
	
sl@0
    88
/**
sl@0
    89
 * A custom wrapping class that allows line breaks between alphabetic and 
sl@0
    90
 * break after classes, but allows (Latin) commas, full-stops,
sl@0
    91
 * closing brackets and tabs to "wrap-up" to the previous line.
sl@0
    92
 */		
sl@0
    93
class TTestCustomWrap3 : public MFormCustomWrap
sl@0
    94
	{
sl@0
    95
sl@0
    96
	TBool LineBreakPossible(TUint aPrevClass,
sl@0
    97
		TUint aNextClass, TBool aHaveSpaces) const
sl@0
    98
		{
sl@0
    99
sl@0
   100
		TBool breakAllowed;
sl@0
   101
		breakAllowed = MFormCustomWrap::LineBreakPossible(aPrevClass,aNextClass,aHaveSpaces);
sl@0
   102
		
sl@0
   103
		if(!breakAllowed)
sl@0
   104
			{
sl@0
   105
			//Specifically allow breaking between alphabetic and break after
sl@0
   106
			//classes (e.g. Tab character)
sl@0
   107
			breakAllowed = ((aPrevClass == MLineBreaker::EAlLineBreakClass) 
sl@0
   108
							&& (aNextClass == MLineBreaker::EBaLineBreakClass));
sl@0
   109
			}
sl@0
   110
		
sl@0
   111
		return breakAllowed;
sl@0
   112
		}
sl@0
   113
	
sl@0
   114
	TBool IsHangingCharacter(TUint aChar) const
sl@0
   115
		{
sl@0
   116
		// Allow commas, full stops, closing brackets and tabs to hang over the
sl@0
   117
		// margins. In practice, ideographic commas, full-stops and brackets
sl@0
   118
		// should be allowed as well as many other types of closing punctuation.
sl@0
   119
		if (aChar == ',' || aChar == '.' || aChar == ')' || aChar == '\t')
sl@0
   120
			return ETrue;
sl@0
   121
		return EFalse;
sl@0
   122
		}
sl@0
   123
	};
sl@0
   124
	
sl@0
   125
/**
sl@0
   126
 * A custom wrapping class that sets tabs as space breaking characters
sl@0
   127
 */	
sl@0
   128
class TTestCustomWrap4 : public MFormCustomWrap
sl@0
   129
	{
sl@0
   130
	TUint LineBreakClass(TUint aCode,TUint& aRangeStart,TUint& aRangeEnd) const
sl@0
   131
		{
sl@0
   132
		TUint breakClass;
sl@0
   133
		
sl@0
   134
		//Set tabs to be space breaking class
sl@0
   135
		if(aCode == 0x09)
sl@0
   136
			{
sl@0
   137
			breakClass = MLineBreaker::ESpLineBreakClass;	
sl@0
   138
			}
sl@0
   139
		else
sl@0
   140
			{
sl@0
   141
			breakClass = MFormCustomWrap::LineBreakClass(aCode,aRangeStart, aRangeEnd);
sl@0
   142
			}
sl@0
   143
		return breakClass;
sl@0
   144
		}
sl@0
   145
	};
sl@0
   146
sl@0
   147
sl@0
   148
#endif