Qt 4.8
Public Functions | Public Variables | List of all members
QTextEngine::LayoutData Struct Reference

#include <qtextengine_p.h>

Public Functions

 LayoutData (const QString &str, void **stack_memory, int mem_size)
 
 LayoutData ()
 
bool reallocate (int totalGlyphs)
 
 ~LayoutData ()
 

Public Variables

int allocated
 
int available_glyphs
 
QGlyphLayout glyphLayout
 
uint hasBidi: 1
 
uint haveCharAttributes: 1
 
QScriptItemArray items
 
uint layoutState: 2
 
unsigned short * logClustersPtr
 
void ** memory
 
uint memory_on_stack: 1
 
QString string
 
int used
 

Detailed Description

Definition at line 428 of file qtextengine_p.h.

Constructors and Destructors

◆ LayoutData() [1/2]

QTextEngine::LayoutData::LayoutData ( const QString str,
void **  stack_memory,
int  mem_size 
)

Definition at line 2219 of file qtextengine.cpp.

2220  : string(str)
2221 {
2222  allocated = _allocated;
2223 
2224  int space_charAttributes = sizeof(HB_CharAttributes)*string.length()/sizeof(void*) + 1;
2225  int space_logClusters = sizeof(unsigned short)*string.length()/sizeof(void*) + 1;
2226  available_glyphs = ((int)allocated - space_charAttributes - space_logClusters)*(int)sizeof(void*)/(int)QGlyphLayout::spaceNeededForGlyphLayout(1);
2227 
2228  if (available_glyphs < str.length()) {
2229  // need to allocate on the heap
2230  allocated = 0;
2231 
2232  memory_on_stack = false;
2233  memory = 0;
2234  logClustersPtr = 0;
2235  } else {
2236  memory_on_stack = true;
2237  memory = stack_memory;
2238  logClustersPtr = (unsigned short *)(memory + space_charAttributes);
2239 
2240  void *m = memory + space_charAttributes + space_logClusters;
2241  glyphLayout = QGlyphLayout(reinterpret_cast<char *>(m), str.length());
2242  glyphLayout.clear();
2243  memset(memory, 0, space_charAttributes*sizeof(void *));
2244  }
2245  used = 0;
2246  hasBidi = false;
2248  haveCharAttributes = false;
2249 }
void clear(int first=0, int last=-1)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static int spaceNeededForGlyphLayout(int totalGlyphs)
unsigned short * logClustersPtr
int length(int item) const

◆ LayoutData() [2/2]

QTextEngine::LayoutData::LayoutData ( )

Definition at line 2206 of file qtextengine.cpp.

◆ ~LayoutData()

QTextEngine::LayoutData::~LayoutData ( )

Definition at line 2251 of file qtextengine.cpp.

2252 {
2253  if (!memory_on_stack)
2254  free(memory);
2255  memory = 0;
2256 }

Functions

◆ reallocate()

bool QTextEngine::LayoutData::reallocate ( int  totalGlyphs)

Definition at line 2258 of file qtextengine.cpp.

2259 {
2260  Q_ASSERT(totalGlyphs >= glyphLayout.numGlyphs);
2261  if (memory_on_stack && available_glyphs >= totalGlyphs) {
2262  glyphLayout.grow(glyphLayout.data(), totalGlyphs);
2263  return true;
2264  }
2265 
2266  int space_charAttributes = sizeof(HB_CharAttributes)*string.length()/sizeof(void*) + 1;
2267  int space_logClusters = sizeof(unsigned short)*string.length()/sizeof(void*) + 1;
2268  int space_glyphs = QGlyphLayout::spaceNeededForGlyphLayout(totalGlyphs)/sizeof(void*) + 2;
2269 
2270  int newAllocated = space_charAttributes + space_glyphs + space_logClusters;
2271  // These values can be negative if the length of string/glyphs causes overflow,
2272  // we can't layout such a long string all at once, so return false here to
2273  // indicate there is a failure
2274  if (space_charAttributes < 0 || space_logClusters < 0 || space_glyphs < 0 || newAllocated < allocated) {
2276  return false;
2277  }
2278 
2279  void **newMem = memory;
2280  newMem = (void **)::realloc(memory_on_stack ? 0 : memory, newAllocated*sizeof(void *));
2281  if (!newMem) {
2283  return false;
2284  }
2285  if (memory_on_stack)
2286  memcpy(newMem, memory, allocated*sizeof(void *));
2287  memory = newMem;
2288  memory_on_stack = false;
2289 
2290  void **m = memory;
2291  m += space_charAttributes;
2292  logClustersPtr = (unsigned short *) m;
2293  m += space_logClusters;
2294 
2295  const int space_preGlyphLayout = space_charAttributes + space_logClusters;
2296  if (allocated < space_preGlyphLayout)
2297  memset(memory + allocated, 0, (space_preGlyphLayout - allocated)*sizeof(void *));
2298 
2299  glyphLayout.grow(reinterpret_cast<char *>(m), totalGlyphs);
2300 
2301  allocated = newAllocated;
2302  return true;
2303 }
char * data()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static int spaceNeededForGlyphLayout(int totalGlyphs)
unsigned short * logClustersPtr
int length(int item) const
void grow(char *address, int totalGlyphs)

Properties

◆ allocated

int QTextEngine::LayoutData::allocated

Definition at line 433 of file qtextengine_p.h.

Referenced by LayoutData(), and reallocate().

◆ available_glyphs

int QTextEngine::LayoutData::available_glyphs

Definition at line 434 of file qtextengine_p.h.

Referenced by LayoutData(), and reallocate().

◆ glyphLayout

QGlyphLayout QTextEngine::LayoutData::glyphLayout

Definition at line 437 of file qtextengine_p.h.

Referenced by LayoutData(), and reallocate().

◆ hasBidi

uint QTextEngine::LayoutData::hasBidi

◆ haveCharAttributes

uint QTextEngine::LayoutData::haveCharAttributes

Definition at line 442 of file qtextengine_p.h.

Referenced by QTextEngine::attributes(), QTextEngine::freeMemory(), and LayoutData().

◆ items

QScriptItemArray QTextEngine::LayoutData::items
mutable

◆ layoutState

uint QTextEngine::LayoutData::layoutState

Definition at line 440 of file qtextengine_p.h.

Referenced by QTextEngine::freeMemory(), LayoutData(), and reallocate().

◆ logClustersPtr

unsigned short* QTextEngine::LayoutData::logClustersPtr

Definition at line 436 of file qtextengine_p.h.

Referenced by QTextLine::layout_helper(), LayoutData(), and reallocate().

◆ memory

void** QTextEngine::LayoutData::memory

Definition at line 435 of file qtextengine_p.h.

Referenced by QTextEngine::attributes(), LayoutData(), reallocate(), and ~LayoutData().

◆ memory_on_stack

uint QTextEngine::LayoutData::memory_on_stack

Definition at line 441 of file qtextengine_p.h.

Referenced by LayoutData(), reallocate(), and ~LayoutData().

◆ string

QString QTextEngine::LayoutData::string

◆ used

int QTextEngine::LayoutData::used
mutable

Definition at line 438 of file qtextengine_p.h.

Referenced by QTextEngine::freeMemory(), and LayoutData().


The documentation for this struct was generated from the following files: