44 #include FT_FREETYPE_H 60 #define U_CTRL_NULL 0x00 84 #define U_CTRL_FS 0x1C 85 #define U_CTRL_GS 0x1D 86 #define U_CTRL_RS 0x1E 87 #define U_CTRL_US 0x1F 91 #define UNICODE_SPACE (' ') 92 #define UNICODE_TAB ('\t') 93 #define UNICODE_LF (0x0a) 94 #define UNICODE_CR (0x0d) 95 #define UNICODE_ESC (0x1b) 96 #define UNICODE_HARD_SPACE (0xa0) 97 #define UNICODE_FIGURE_SPACE (0x2007) 98 #define UNICODE_APOSTROPHE_N (0x0149) 99 #define UNICODE_HYPER_ANCHOR_START (0x41) 100 #define UNICODE_HYPER_ANCHOR_END (0x61) 101 #define UNICODE_TEXT_COLOUR_START (0x43) 102 #define UNICODE_TEXT_COLOUR_END (0x63) 103 #define UNICODE_HYPER_ATTRIB_START (0x44) 104 #define UNICODE_HYPER_ATTRIB_END (0x64) 107 #define UNICODE_QUOTE ('"') 108 #define UNICODE_LEFT_ROUND ('(') 109 #define UNICODE_LEFT_SQUARE ('[') 110 #define UNICODE_LEFT_CURLY ('{') 111 #define UNICODE_LEFT_DQUOTE 0x201C 112 #define UNICODE_LEFT_PANGLE 0x2039 113 #define UNICODE_LEFT_FULL_CURLY 0xFF5B 114 #define UNICODE_LEFT_FULL_ROUND 0xFF08 115 #define UNICODE_LEFT_FULL_SQUARE 0xFF3B 116 #define UNICODE_LEFT_FULL_DROUND 0xFF5F 117 #define UNICODE_LEFT_FULL_DQUOTE 0xFF02 120 #define UNICODE_QUOTE ('"') 121 #define UNICODE_RIGHT_ROUND (')') 122 #define UNICODE_RIGHT_SQUARE (']') 123 #define UNICODE_RIGHT_CURLY ('}') 124 #define UNICODE_RIGHT_DQUOTE 0x201D 125 #define UNICODE_RIGHT_PANGLE 0x203A 126 #define UNICODE_RIGHT_FULL_CURLY 0xFF5D 127 #define UNICODE_RIGHT_FULL_ROUND 0xFF09 128 #define UNICODE_RIGHT_FULL_SQUARE 0xFF3D 129 #define UNICODE_RIGHT_FULL_DROUND 0xFF60 130 #define UNICODE_RIGHT_FULL_DQUOTE 0xFF02 131 #define UNICODE_FULL_QUESTIONMARK 0xFF1F 132 #define UNICODE_QUESTIONMARK 0x003F 133 #define UNICODE_EXCLAMATIONMARK 0x0021 134 #define UNICODE_FULL_STOP ('.') 135 #define UNICODE_COMMA (',') 136 #define UNICODE_COMMA_FULL 0xFF0C 137 #define UNICODE_FULL_STOP_FULL 0xFF0E 138 #define UNICODE_COLON (':') 139 #define UNICODE_SEMICOLON (';') 140 #define UNICODE_FULL_SEMICOLON 0xFF1B 141 #define IDEOGRAPHIC_COMMA 0x3001 142 #define IDEOGRAPHIC_FULL_STOP 0x3002 144 #define HIGH_SURROGATE_START 0xD800 145 #define HIGH_SURROGATE_END 0xDBFF 146 #define LOW_SURROGATE_START 0xDC00 147 #define LOW_SURROGATE_END 0xDFFF 148 #define FULL_ADVANCE 1 149 #define HALF_ADVANCE 2 153 #define DIV(x, y) ((((x) * 10) / (y) + 5) / 10) 155 #define DIV(x, y) ((x) / (y)) 159 #define SCALE_X_TO_HD(X) DIV((X * mg_ctxt.osd_x.mlt), mg_ctxt.osd_x.div) 160 #define SCALE_Y_TO_HD(Y) DIV((Y * mg_ctxt.osd_y.mlt), mg_ctxt.osd_y.div) 163 #define IS_WHITESPACE(X) ((X) == UNICODE_SPACE || (X) == UNICODE_TAB) 165 #define SRC_FORE_MAX 255 166 #define FactorForeAlpha(fore_value, fore_col) fore_value *= (fore_col >> 24) 167 #define NotTransTDColor( col ) ((col >> 12) != 0x0) 168 #define NotOpaqueTDColor( col ) ((col >> 12) != 0xf) 174 typedef struct fontLibrary_s
180 typedef struct metrics_s
190 typedef struct textChar_s
197 struct textChar_s *next;
198 struct textChar_s *previous;
202 typedef struct textLine_s
204 textChar_t *firstChar;
205 textChar_t *lastChar;
209 struct textLine_s *next;
210 struct textLine_s *previous;
211 struct textItem_s *parentObject;
215 typedef void (*justify_fn)(
struct textItem_s *textObject);
218 typedef struct textItem_s
222 justify_fn vJustify, hJustify;
229 textLine_t *firstLine;
230 textLine_t *lastLine;
234 typedef struct colourNode_s
237 struct colourNode_s *previous;
243 static fontLibrary_t *font = NULL;
244 static colourNode_t *colourStack = NULL;
247 static metrics_t metrics24Point = {22, 11, 1, -3, 18};
248 static metrics_t metrics26Point = {24, 12, 1, -3, 20};
249 static metrics_t metrics31Point = {28, 14, 1, -4, 23};
250 static metrics_t metrics36Point = {32, 16, 2, -4, 27};
263 static void DestructColourStack(
void)
265 colourNode_t *previous;
266 while (colourStack != NULL)
268 previous = colourStack->previous;
270 colourStack = previous;
279 static void InitColourStack(
OSDColor colour)
281 if (colourStack != NULL)
283 DestructColourStack();
286 colourStack->previous = NULL;
287 colourStack->colour = colour;
295 static void PushColour(
OSDColor colour)
299 new->previous = colourStack;
300 new->colour = colour;
312 colourNode_t *previous;
313 if (colourStack->previous != NULL)
315 previous = colourStack->previous;
317 colourStack = previous;
319 return colourStack->colour;
341 bytesLeft = tagLength;
345 if (((*cursor) & 0x08) != 0)
354 if (((*cursor) & 0x40) != 0)
356 linkColourEnabled =
TRUE;
358 if (((*cursor) & 0x20) != 0)
360 activeColourEnabled =
TRUE;
362 if (((*cursor) & 0x10) != 0)
364 visitedColourEnabled =
TRUE;
368 if (bytesLeft >= 4 && linkColourEnabled)
374 if (bytesLeft >= 4 && activeColourEnabled)
380 if (bytesLeft >= 4 && visitedColourEnabled)
388 return string + tagLength + 1;
447 static void ScaleAllToHD(textItem_t *textObject)
449 textLine_t *currentLine;
450 textChar_t *currentChar;
453 textObject->boxX = SCALE_X_TO_HD(textObject->boxX);
454 textObject->boxY = SCALE_Y_TO_HD(textObject->boxY);
457 currentLine = textObject->firstLine;
458 while (currentLine != NULL)
461 currentLine->position = SCALE_Y_TO_HD(currentLine->position);
463 currentChar = currentLine->firstChar;
464 while (currentChar != NULL)
467 currentChar->position = SCALE_X_TO_HD(currentChar->position);
468 currentChar = currentChar->next;
470 currentLine = currentLine->next;
479 static textChar_t* NewCharacter(
U32BIT *pCharacter)
485 newChar->uchar = *pCharacter;
486 newChar->next = NULL;
496 static textLine_t* NewLine(textItem_t *parent)
503 newLine->firstChar = NULL;
504 newLine->lastChar = NULL;
505 newLine->fullCharCount = 0;
506 newLine->halfCharCount = 0;
507 newLine->next = NULL;
508 newLine->parentObject = parent;
510 if (parent->lastLine != NULL)
512 parent->lastLine->next = newLine;
513 newLine->previous = parent->lastLine;
517 newLine->previous = NULL;
520 parent->lastLine = newLine;
532 static void DeleteChar(textChar_t *pChar, textLine_t *line)
534 if (pChar->advanceType == FULL_ADVANCE)
536 line->fullCharCount--;
538 else if (pChar->advanceType == HALF_ADVANCE)
540 line->halfCharCount--;
551 static void DeleteRemainingChars(textChar_t *pChar, textLine_t *line)
553 textChar_t *cursor, *next;
556 if (pChar->previous != NULL)
558 pChar->previous->next = NULL;
561 while (cursor != NULL)
564 DeleteChar(cursor, line);
574 static void DestructLine(textLine_t *line)
576 DeleteRemainingChars(line->firstChar, line);
585 static void DestructTextObject(textItem_t *text)
587 textLine_t *cursor, *next;
589 cursor = text->firstLine;
590 while (cursor != NULL)
593 DestructLine(cursor);
606 static BOOLEAN CharIsPrintable(
U16BIT uchar,
int characterSet)
610 if (characterSet == 12)
650 pixels = (points * 45) / 56;
653 pixels = (points * 45) / 64;
664 static U32BIT GetLineLengthPixels(textLine_t *line)
670 U32BIT fullCharCount = line->fullCharCount;
671 U32BIT halfCharCount = line->halfCharCount;
673 text = line->parentObject;
675 letterSpaces = DIV(((fullCharCount + halfCharCount - 1) * text->attribs->letter_space), 255);
677 charsWidth = ((fullCharCount * text->metrics->fullAdvance) + (halfCharCount * text->metrics->halfAdvance));
679 lineLengthPts = charsWidth + letterSpaces + text->metrics->xOffsetLeft;
683 return lineLengthPts;
686 lineLengthPixels = PointsToPixels(lineLengthPts, line->parentObject->attribs);
687 return lineLengthPixels;
700 if (character >= 0xF900 && character <= 0xFAFF)
702 else if (character >= 0x3190 && character <= 0x319F)
704 else if (character >= 0x4E00 && character <= 0x9FFF)
706 else if (character >= 0x3200 && character <= 0x32FF)
724 case UNICODE_RIGHT_ROUND:
725 case UNICODE_RIGHT_SQUARE:
726 case UNICODE_RIGHT_CURLY:
727 case UNICODE_RIGHT_DQUOTE:
728 case UNICODE_RIGHT_PANGLE:
729 case UNICODE_RIGHT_FULL_CURLY:
730 case UNICODE_RIGHT_FULL_ROUND:
731 case UNICODE_RIGHT_FULL_SQUARE:
732 case UNICODE_RIGHT_FULL_DROUND:
733 case UNICODE_RIGHT_FULL_DQUOTE:
734 case UNICODE_QUESTIONMARK:
735 case UNICODE_FULL_QUESTIONMARK:
736 case UNICODE_EXCLAMATIONMARK:
737 case UNICODE_FULL_STOP:
739 case UNICODE_FULL_STOP_FULL:
740 case UNICODE_COMMA_FULL:
742 case UNICODE_SEMICOLON:
743 case UNICODE_FULL_SEMICOLON:
745 case IDEOGRAPHIC_COMMA:
746 case IDEOGRAPHIC_FULL_STOP:
764 case UNICODE_LEFT_ROUND:
765 case UNICODE_LEFT_SQUARE:
766 case UNICODE_LEFT_CURLY:
767 case UNICODE_LEFT_DQUOTE:
768 case UNICODE_LEFT_PANGLE:
769 case UNICODE_LEFT_FULL_CURLY:
770 case UNICODE_LEFT_FULL_ROUND:
771 case UNICODE_LEFT_FULL_SQUARE:
772 case UNICODE_LEFT_FULL_DROUND:
773 case UNICODE_LEFT_FULL_DQUOTE:
787 static void DeleteFollowingWhitespace(textLine_t *line)
790 cursor = line->lastChar;
791 while (IS_WHITESPACE(cursor->uchar))
793 cursor = cursor->previous;
795 if (cursor->next != NULL)
797 DeleteRemainingChars(cursor->next, line);
807 static void DoWrapping(textItem_t *text)
809 textLine_t *currentLine;
814 currentLine = text->lastLine;
817 if (GetLineLengthPixels(currentLine) > text->boxX)
819 cursor = currentLine->lastChar;
822 if (IS_WHITESPACE(cursor->uchar))
824 currentLine->lastChar = cursor->previous;
825 currentLine->lastChar->next = NULL;
826 DeleteChar(cursor, currentLine);
827 if (text->lineCount < text->maxLines)
834 while (!breakFound && cursor != NULL)
836 if (IS_WHITESPACE(cursor->uchar))
839 if (cursor->next != NULL)
841 cursor = cursor->next;
846 else if (DontBreakBefore(cursor->uchar) || DontBreakAfter(cursor->previous->uchar))
848 cursor = cursor->previous;
851 else if (IsBreakable(cursor->uchar) || IsBreakable(cursor->previous->uchar))
857 cursor = cursor->previous;
864 newLine = NewLine(text);
865 cursor->previous->next = NULL;
866 newLine->lastChar = currentLine->lastChar;
867 currentLine->lastChar = cursor->previous;
868 newLine->firstChar = cursor;
869 newLine->firstChar->previous = NULL;
872 for (cursor = newLine->firstChar; cursor != NULL; cursor = cursor->next)
875 if (cursor->advanceType == FULL_ADVANCE)
877 currentLine->fullCharCount--;
878 newLine->fullCharCount++;
880 else if (cursor->advanceType == HALF_ADVANCE)
882 currentLine->halfCharCount--;
883 newLine->halfCharCount++;
887 DeleteFollowingWhitespace(currentLine);
899 static void AddChar(
U32BIT *character, textItem_t *text,
OSDColor colour)
901 textLine_t *currentLine;
904 currentLine = text->lastLine;
906 newChar = NewCharacter(character);
907 if (currentLine->firstChar == NULL)
909 currentLine->firstChar = newChar;
911 newChar->previous = currentLine->lastChar;
912 if (currentLine->lastChar != NULL)
914 currentLine->lastChar->next = newChar;
916 currentLine->lastChar = newChar;
917 newChar->colour = colour;
919 if (*character < 0x1fff)
921 currentLine->halfCharCount++;
922 newChar->advanceType = HALF_ADVANCE;
923 newChar->advance = text->metrics->halfAdvance;
927 currentLine->fullCharCount++;
928 newChar->advanceType = FULL_ADVANCE;
929 newChar->advance = text->metrics->fullAdvance;
943 static void AddCaret(textItem_t *text)
945 textLine_t *currentLine;
948 currentLine = text->lastLine;
951 switch (text->attribs->caret)
954 character = (
U32BIT *)&insert_caret;
957 character = (
U32BIT *)&overwrite_caret;
961 newChar = NewCharacter(character);
962 if (currentLine->firstChar == NULL)
964 currentLine->firstChar = newChar;
966 newChar->previous = currentLine->lastChar;
967 if (currentLine->lastChar != NULL)
969 currentLine->lastChar->next = newChar;
971 currentLine->lastChar = newChar;
972 newChar->colour = text->attribs->fore_colour;
974 if (text->attribs->entry_point == text->charsLen)
976 currentLine->halfCharCount++;
977 newChar->advanceType = HALF_ADVANCE;
978 newChar->advance = text->metrics->halfAdvance;
982 newChar->advanceType = NO_ADVANCE;
983 newChar->advance = 0;
998 static void GetMaxLines(textItem_t *text)
1002 Ymin = 0 - text->metrics->yMin;
1003 Ymax = text->metrics->yMax;
1004 text->maxLines = ((text->boxY - (Ymax + Ymin)) / text->attribs->line_space) + 1;
1014 static void FillLines(textItem_t *text)
1018 U16BIT high_surrogate = 0;
1019 text->firstLine = NewLine(text);
1020 text->lastLine = text->firstLine;
1022 markupColour = text->attribs->fore_colour;
1025 for (currentChar = text->chars; currentChar < text->chars + (text->charsLen); currentChar++)
1027 if (*currentChar >= HIGH_SURROGATE_START && *currentChar <= HIGH_SURROGATE_END)
1029 high_surrogate = *currentChar;
1033 if (high_surrogate && *currentChar >= LOW_SURROGATE_START && *currentChar <= LOW_SURROGATE_END)
1037 U32BIT unicode_character;
1039 X = (high_surrogate & 0x3F) << 10 | (*currentChar & 0x3FF);
1040 U = ((high_surrogate >> 6) & 0x1F) + 1;
1041 unicode_character = (U << 16) | X;
1043 AddChar(&unicode_character, text, markupColour);
1048 else if (high_surrogate)
1054 if (currentChar - text->chars == text->attribs->entry_point)
1071 switch (*currentChar)
1075 if (*currentChar == 4)
1078 markupColour = (*currentChar << 16) & 0xff0000;
1080 markupColour |= (*currentChar << 8) & 0xff00;
1082 markupColour |= *currentChar & 0xff;
1084 markupColour |= ((255 - *currentChar) << 24) & 0xff000000;
1085 PushColour(markupColour);
1089 markupColour = PopColour();
1092 currentChar = ReadHyperAttribs(currentChar, text->attribs->p_ha);
1095 currentChar = AddHyperAnchor(currentChar, text->attribs->p_ha);
1096 markupColour = colourStack->colour;
1099 EndHyperAnchor(currentChar, text->attribs->p_ha);
1100 markupColour = colourStack->colour;
1106 else if (CharIsPrintable(*currentChar, text->attribs->character_set))
1108 U32BIT unicode_character = *currentChar;
1109 AddChar(&unicode_character, text, markupColour);
1112 if (text->attribs->entry_point == text->charsLen)
1121 static void JustifyHStart(textItem_t *textObject)
1123 textLine_t *currentLine;
1124 textChar_t *currentChar;
1127 currentLine = textObject->firstLine;
1128 while (currentLine != NULL)
1130 currentChar = currentLine->firstChar;
1131 cursor = textObject->metrics->xOffsetLeft;
1133 while (currentChar != NULL)
1135 currentChar->position = cursor;
1136 if (cursor + (
S32BIT)currentChar->advance > (
S32BIT)textObject->boxX)
1138 currentLine->lastChar = currentChar->previous;
1139 DeleteRemainingChars(currentChar, currentLine);
1145 cursor += (
S32BIT)currentChar->advance;
1146 currentChar = currentChar->next;
1150 currentLine = currentLine->next;
1157 static void JustifyHCentre(textItem_t *textObject)
1159 textLine_t *currentLine;
1160 textChar_t *currentChar;
1164 currentLine = textObject->firstLine;
1165 while (currentLine != NULL)
1167 lineLength = GetLineLengthPixels(currentLine);
1168 cursor = ((
S32BIT)textObject->boxX - lineLength) / 2;
1169 currentChar = currentLine->firstChar;
1171 while (currentChar != NULL)
1173 currentChar->position = cursor;
1174 if (cursor + (
S32BIT)currentChar->advance > (
S32BIT)textObject->boxX)
1176 currentLine->lastChar = currentChar->previous;
1177 DeleteRemainingChars(currentChar, currentLine);
1181 else if (cursor < textObject->metrics->xOffsetLeft)
1183 currentLine->firstChar = currentChar->next;
1184 cursor += (
S32BIT)currentChar->advance;
1185 DeleteChar(currentChar, currentLine);
1186 currentLine->firstChar->previous = NULL;
1188 currentChar = currentLine->firstChar;
1192 cursor += (
S32BIT)currentChar->advance;
1193 currentChar = currentChar->next;
1197 currentLine = currentLine->next;
1204 static void JustifyHEnd(textItem_t *textObject)
1206 textLine_t *currentLine;
1207 textChar_t *currentChar;
1210 currentLine = textObject->lastLine;
1211 while (currentLine != NULL)
1213 currentChar = currentLine->lastChar;
1214 cursor = textObject->boxX - (
S32BIT)currentChar->advance;
1216 while (currentChar != NULL)
1218 currentChar->position = cursor;
1219 if (cursor < textObject->metrics->xOffsetLeft)
1222 currentChar = currentChar->next;
1223 currentChar->previous->next = NULL;
1224 DeleteRemainingChars(currentLine->firstChar, currentLine);
1225 currentLine->firstChar = currentChar;
1226 currentChar->previous = NULL;
1231 currentChar = currentChar->previous;
1232 if (currentChar != NULL)
1234 cursor -= (
S32BIT)currentChar->advance;
1239 currentLine = currentLine->previous;
1247 static void JustifyVStart(textItem_t *textObject)
1249 textLine_t *currentLine;
1256 currentLine = textObject->firstLine;
1258 yMaxPixels = textObject->metrics->yMax;
1260 cursor = yMaxPixels;
1264 while (currentLine != NULL)
1266 currentLine->position = cursor;
1267 cursor += textObject->attribs->line_space;
1269 if (lineCount > textObject->maxLines)
1275 currentLine = currentLine->next;
1279 if (currentLine != NULL)
1281 currentLine->previous->next = NULL;
1282 while (currentLine != NULL)
1284 next = currentLine->next;
1285 DestructLine(currentLine);
1295 static void JustifyVCentre(textItem_t *textObject)
1297 textLine_t *currentLine;
1299 U32BIT yMaxPixels, yMinPixels;
1303 currentLine = textObject->firstLine;
1305 yMaxPixels = textObject->metrics->yMax;
1306 yMinPixels = 0 - textObject->metrics->yMin;
1308 linesHeight = yMaxPixels + yMinPixels + (textObject->attribs->line_space * (textObject->lineCount - 1));
1309 cursor = (textObject->boxY - linesHeight) / 2;
1310 cursor += yMaxPixels;
1312 while (currentLine != NULL)
1314 currentLine->position = cursor;
1315 cursor += textObject->attribs->line_space;
1316 currentLine = currentLine->next;
1324 static void JustifyVEnd(textItem_t *textObject)
1326 textLine_t *currentLine;
1331 currentLine = textObject->lastLine;
1333 yMinPixels = 0 - textObject->metrics->yMin;
1335 cursor = textObject->boxY - yMinPixels;
1340 while (currentLine != NULL)
1342 currentLine->position = cursor;
1343 cursor -= textObject->attribs->line_space;
1344 currentLine = currentLine->previous;
1353 static BOOLEAN CreateSurface(textItem_t *textObject)
1358 if (textObject->canvas != NULL)
1372 textObject->attribs->back_colour);
1375 if (textObject->canvas->hw_handle != NULL)
1377 textObject->canvas->width = textObject->boxX;
1378 textObject->canvas->height = textObject->boxY;
1395 U32BIT fa, ba, comp, tmp_c, alpha_c;
1398 FactorForeAlpha(fore_value, fore_col);
1400 alpha_c = ((((255 ^ ba) * fore_value) + 32512) / 65025) + ba;
1401 fa = (
U8BIT)(fore_value / SRC_FORE_MAX);
1402 ba = (((255 ^ fa) * ba) + 127) / 255;
1403 tmp_c = alpha_c << 24;
1404 comp = ba * ((*pixel >> 16) & 0xff) + fa * ((fore_col >> 16) & 0xff);
1405 tmp_c |= ((comp + (alpha_c >> 1)) / alpha_c) << 16;
1406 comp = ba * ((*pixel >> 8) & 0xff) + fa * ((fore_col >> 8) & 0xff);
1407 tmp_c |= ((comp + (alpha_c >> 1)) / alpha_c) << 8;
1408 comp = ba * (*pixel & 0xff) + fa * (fore_col & 0xff);
1409 tmp_c |= ((comp + (alpha_c >> 1)) / alpha_c);
1422 U32BIT fa, ba, comp, tmp_c, alpha_c;
1425 FactorForeAlpha(fore_value, fore_col);
1428 alpha_c = ((((15 - ba) * fore_value) + 1912) / 3825) + comp;
1429 fa = (
U8BIT)(fore_value / SRC_FORE_MAX);
1430 ba = (((255 ^ fa) * comp) + 127) / 255;
1431 tmp_c = (alpha_c / 17) << 12;
1432 comp = ba * ((*pixel >> 8) & 0xf) + fa * ((temp_col >> 8) & 0xf);
1433 tmp_c |= ((comp + (alpha_c >> 1)) / alpha_c) << 8;
1434 comp = ba * ((*pixel >> 4) & 0xf) + fa * ((temp_col >> 4) & 0xf);
1435 tmp_c |= ((comp + (alpha_c >> 1)) / alpha_c) << 4;
1436 comp = ba * (*pixel & 0xf) + fa * (temp_col & 0xf);
1437 tmp_c |= ((comp + (alpha_c >> 1)) / alpha_c);
1449 static void RenderChar(FT_GlyphSlot glyph, textLine_t *line, textChar_t *charObject)
1455 U8BIT *src_buffer, *dest_buffer;
1462 canvas = line->parentObject->canvas;
1464 glyphHeight = glyph->bitmap.rows;
1466 penX = charObject->position + glyph->bitmap_left;
1467 penY = line->position - glyph->bitmap_top;
1469 src_buffer = (
U8BIT *)glyph->bitmap.buffer;
1472 fore_colour = charObject->colour;
1473 if (NotOpaqueTDColor( fore_colour ))
1477 for (row_count = 0; row_count != glyphHeight && penY < canvas->
height; row_count++)
1485 for (a_point = 0; a_point != glyph->bitmap.width && penX < canvas->
width; a_point++)
1492 src_pixel = &src_buffer[(row_count * glyph->bitmap.pitch) + a_point];
1495 dest_pixel = (
OSDColor *)&dest_buffer[((penY * canvas->
buff_pitch / 2) + (penX)) * 2];
1496 fore_value = *src_pixel;
1499 BlendColours16((
HD2Color *)dest_pixel, fore_value, fore_colour );
1504 dest_pixel = (
OSDColor *)&dest_buffer[((penY * canvas->
buff_pitch / 4) + (penX)) * 4];
1505 fore_value = *src_pixel;
1508 BlendColours32( dest_pixel, fore_value, fore_colour );
1514 penX = charObject->position + glyph->bitmap_left;
1524 static BOOLEAN Render(textItem_t *textObject)
1527 textLine_t *currentLine;
1528 textChar_t *currentChar;
1534 fontWidth = PointsToPixels(textObject->attribs->font.fp.size, textObject->attribs);
1535 fontHeight = textObject->attribs->font.fp.size;
1540 success = CreateSurface(textObject);
1543 canvas = textObject->canvas;
1547 FT_Set_Pixel_Sizes(font->face, fontWidth, fontHeight);
1549 currentLine = textObject->firstLine;
1551 while (currentLine != NULL && success)
1553 currentChar = currentLine->firstChar;
1555 while (currentChar != NULL && success)
1558 err = FT_Load_Char( font->face, currentChar->uchar, FT_LOAD_RENDER );
1561 RenderChar(font->face->glyph, currentLine, currentChar);
1567 currentChar = currentChar->next;
1569 currentLine = currentLine->next;
1582 fontLibrary_t *newFontLibrary;
1588 if (newFontLibrary != NULL)
1590 ftErr = FT_Init_FreeType( &newFontLibrary->library );
1595 newFontLibrary = NULL;
1602 if (mhErr ==
MHERR_OK && fontFileData != NULL)
1606 ftErr = FT_New_Face( newFontLibrary->library, (
char *)fontFileData->
data, 0, &newFontLibrary->face );
1610 ftErr = FT_New_Memory_Face( newFontLibrary->library,
1611 (FT_Byte *)fontFileData->
data,
1614 &newFontLibrary->face );
1620 newFontLibrary = NULL;
1626 newFontLibrary = NULL;
1629 return newFontLibrary;
1641 textItem_t *newItem;
1644 if (newItem != NULL)
1649 newItem->metrics = &metrics24Point;
1652 newItem->metrics = &metrics26Point;
1655 newItem->metrics = &metrics31Point;
1658 newItem->metrics = &metrics36Point;
1665 if (newItem != NULL)
1667 newItem->firstLine = NULL;
1668 newItem->lastLine = NULL;
1669 newItem->lineCount = 0;
1670 newItem->chars = unistr.
data;
1671 newItem->charsLen = unistr.
len;
1672 newItem->attribs = attrib;
1673 newItem->boxX = txt_box.
width;
1674 newItem->boxY = txt_box.
height;
1680 newItem->hJustify = JustifyHStart;
1683 newItem->hJustify = JustifyHEnd;
1686 newItem->hJustify = JustifyHCentre;
1696 newItem->vJustify = JustifyVStart;
1699 newItem->vJustify = JustifyVEnd;
1702 newItem->vJustify = JustifyVCentre;
1721 textItem_t *textObject;
1725 textObject = InitText(unistr, attrib, txt_box);
1728 font = InitFreetype(attrib);
1736 GetMaxLines(textObject);
1739 if (textObject != NULL)
1741 FillLines(textObject);
1744 DestructColourStack();
1746 if (textObject != NULL && textObject->hJustify != NULL)
1748 textObject->hJustify(textObject);
1755 if (textObject != NULL && textObject->vJustify != NULL)
1757 textObject->vJustify(textObject);
1766 textChar_t *character;
1769 line = textObject->firstLine;
1772 character = line->firstChar;
1776 character = character->next;
1786 ScaleAllToHD(textObject);
1787 success = Render(textObject);
1792 renderedSurface = textObject->canvas;
1794 if (textObject != NULL)
1796 DestructTextObject(textObject);
1799 return renderedSurface;
E_MhegErr DVB_MhegGetEmbeddedFont(const U8BIT *fontName, S_FontData **fontData)
Retrieves the specified embedded font. Depending on the requirements of the platform, it may either pass back:
#define JUSTIFY_H_JUSTIFIED
void STB_MemFree(void *ptr)
Releases previously allocated memory.
#define MakeHD2Color(osdcol)
#define COLOUR_FORMAT_ARGB4444
void * STB_OSDMhegCreateSurface(U16BIT width, U16BIT height, BOOLEAN init, U32BIT colour)
Creates a hardware surface on which MHEG5 engine will draw an individual MHEG object. At its basic the function can just allocate the buffer to be returned by STB_OSDMhegLockBuffer(). It's size being: (width * height * bytes_per_pixel) Also, when 'init' is TRUE, function initialises surface buffer to the specified colour. For pixel colour format of less than four bytes, use least significant bits of 'colour'.
#define ENTRY_INSERT_CHAR
#define UNICODE_TEXT_COLOUR_START
#define UNICODE_HYPER_ANCHOR_START
void * STB_MemAlloc(U32BIT memSize)
Allocates the specified number of bytes.
#define FONT_STYLE_SQUARE
#define UNICODE_HYPER_ANCHOR_END
#define JUSTIFY_V_JUSTIFIED
Font loading functions required by MHEG5 engine (Hong Kong profile)
#define ENTRY_OVERWRITE_CHAR
#define COLOUR_FORMAT_ARGB8888
#define UNICODE_FIGURE_SPACE
#define UNICODE_HARD_SPACE
void * STB_OSDMhegLockBuffer(void *surface, U32BIT *pPitch)
Converts hardware surface handle returned by STB_OSDMhegCreateSurface() to buffer address that the en...
Interface to the MHEG text render that uses Freetype font library.
#define JUSTIFY_VERTI_MASK
#define UNICODE_HYPER_ATTRIB_START
#define UNICODE_TEXT_COLOUR_END
Interface to the MHEG text render that uses Freetype font library.
Graphics functions required by the HD MHEG5 engine. All references to colour used in these functions ...
void STB_OSDMhegUnlockBuffer(void *surface)
This function informs HW that MHEG5 is finished writing to the buffer.
union _DrawTextAttrib::@14 font