// Loads a FreeType face. void* FontDatabase::LoadFace(const String& file_name) { FileInterface* file_interface = GetFileInterface(); FileHandle handle = file_interface->Open(file_name); if (!handle) { return false; } // Seek to the end of the file so we can determine its size. if (!file_interface->Seek(handle, 0, SEEK_END)) { file_interface->Close(handle); return false; } size_t length = file_interface->Tell(handle); file_interface->Seek(handle, 0, SEEK_SET); FT_Byte* buffer = new FT_Byte[length]; file_interface->Read(buffer, length, handle); file_interface->Close(handle); return LoadFace(buffer, length, file_name, true); }
FT_Face GetFace( filter_t *p_filter, vlc_font_t *p_font ) { filter_sys_t *p_sys = p_filter->p_sys; if( p_font->p_face ) return p_font->p_face; p_font->p_face = LoadFace( p_filter, p_font->psz_fontfile, p_font->i_index, p_sys->p_default_style ); return p_font->p_face; }
FX_BOOL CFGAS_FontMgrImp::VerifyUnicode(CFX_FontDescriptor* pDesc, FX_WCHAR wcUnicode) { IFX_FileRead* pFileRead = CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); if (!pFileRead) return FALSE; FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); pFileRead->Release(); if (!pFace) return FALSE; if (FXFT_Get_Face_External_Stream(pFace)) FXFT_Clear_Face_External_Stream(pFace); FXFT_Done_Face(pFace); return !retCharmap && retIndex; }
void CFGAS_FontMgr::RegisterFaces(IFX_SeekableReadStream* pFontStream, const CFX_WideString* pFaceName) { int32_t index = 0; int32_t num_faces = 0; do { FXFT_Face pFace = LoadFace(pFontStream, index++); if (!pFace) continue; // All faces keep number of faces. It can be retrieved from any one face. if (num_faces == 0) num_faces = pFace->num_faces; RegisterFace(pFace, pFaceName); if (FXFT_Get_Face_External_Stream(pFace)) FXFT_Clear_Face_External_Stream(pFace); FXFT_Done_Face(pFace); } while (index < num_faces); }
// Loads a FreeType face. void* FontProvider::LoadFace(const String& file_name) { FileInterface* file_interface = GetFileInterface(); FileHandle handle = file_interface->Open(file_name); if (!handle) { return NULL; } size_t length = file_interface->Length(handle); FT_Byte* buffer = new FT_Byte[length]; file_interface->Read(buffer, length, handle); file_interface->Close(handle); return LoadFace(buffer, (int)length, file_name, true); }
CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName, int32_t iFaceIndex, int32_t* pFaceCount) { CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); if (!pFontMapper) return nullptr; IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); if (!pSystemFontInfo) return nullptr; IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode()); if (!pFontStream) return nullptr; if (!LoadFace(pFontStream, 0)) { pFontStream->Release(); return nullptr; } CFX_Font* pInternalFont = new CFX_Font(); if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { pFontStream->Release(); return nullptr; } CFGAS_GEFont* pFont = CFGAS_GEFont::LoadFont(pInternalFont, this); if (!pFont) { pFontStream->Release(); return nullptr; } m_IFXFont2FileRead.SetAt(pFont, pFontStream); if (pFaceCount) *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; return pFont; }
void CFaceCtrl::SetCurPage(int nPageIndex) { if (NULL == m_lpFaceList) return; int nCount = (int)m_lpFaceList->m_arrFaceInfo.size(); int nOnePage = m_nRow * m_nCol; if (nCount > 0 && nOnePage > 0) { if (nCount % nOnePage == 0) m_nPageCnt = nCount / nOnePage; else m_nPageCnt = nCount / nOnePage + 1; } else m_nPageCnt = 0; if (nPageIndex < 0 || nPageIndex >= m_nPageCnt) return; m_nCurPage = nPageIndex; LoadFace(m_nCurPage); }
FT_Face SelectAndLoadFace( filter_t *p_filter, const text_style_t *p_style, uni_char_t codepoint ) { filter_sys_t *p_sys = p_filter->p_sys; const char *psz_fontname = (p_style->i_style_flags & STYLE_MONOSPACED) ? p_style->psz_monofontname : p_style->psz_fontname; bool b_bold = p_style->i_style_flags & STYLE_BOLD; bool b_italic = p_style->i_style_flags & STYLE_ITALIC; FT_Face p_face = NULL; int i_idx = 0; char *psz_fontfile = NULL; if( p_sys->pf_select ) psz_fontfile = p_sys->pf_select( p_filter, psz_fontname, b_bold, b_italic, &i_idx, codepoint ); else psz_fontfile = NULL; if( !psz_fontfile || *psz_fontfile == '\0' ) { msg_Warn( p_filter, "SelectAndLoadFace: no font found for family: %s, codepoint: 0x%x", psz_fontname, codepoint ); free( psz_fontfile ); return NULL; } p_face = LoadFace( p_filter, psz_fontfile, i_idx, p_style ); free( psz_fontfile ); return p_face; }
int Model::ReadAndSaveValues() { int CurrentMaterial = 0 ; for (int i = 0; i < coords.size(); ++i) { if ( (*coords[i])[0] == '#') continue; else if ((*coords[i])[0] == 'v' && (*coords[i])[1] == ' ')//vertex { float x, y, z; sscanf_s(coords[i]->c_str(), "v %f %f %f", &x, &y, &z); vertex.push_back(new Vector3(x, y, z)); } else if ((*coords[i])[0] == 'v' && (*coords[i])[1] == 'n' && ControlNormal)//normal { float x, y, z; sscanf_s(coords[i]->c_str(), "vn %f %f %f", &x, &y, &z); normals.push_back(new Vector3(x, y, z)); IsNormal = true ; } else if ((*coords[i])[0] == 'f')//face { LoadFace(i, CurrentMaterial) ; } if(ControlMaterial) { if((*coords[i])[0] == 'u' && (*coords[i])[1] == 's' && (*coords[i])[2] == 'e') // search for material and make index equal to it { char materialIndx[200] ; sscanf(coords[i]->c_str() , "usemtl %s" , materialIndx ) ; for(int j = 0 ; j < materials.size() ; ++j) { if(strcmp(materials[j]->name.c_str(), materialIndx) == 0 ) { CurrentMaterial = j ; break ; } } } else if((*coords[i])[0] == 'm' && (*coords[i])[1] == 't' && (*coords[i])[2] == 'l' && (*coords[i])[3] == 'l') // load the materialfile { int Correct = LoadMaterial(i) ; if(Correct == -1) return -1 ; } } if(ControlTexture) if((*coords[i])[0] == 'v' && (*coords[i])[0] == 't') { TexCoord* texloc = new TexCoord(0,0) ; scanf(coords[i]->c_str() , "vt %f %f" , &texloc->U , &texloc->V); texloc->V = 1- texloc->V ; // reverse it texcoordinates.push_back(texloc) ; IsTexture = true ; delete texloc ; } if(materials.size() == 0) IsMaterial = false ; else IsMaterial = true ; } return 0 ; }
void read_obj(const char* strName) { int i,j,k; FILE *fp; int nwords; char *comment_ptr; char *first_word; float x,y,z,w; /* read from standard input */ fp = fopen(strName,"r"); while (1) { comment_ptr = fetch_line (fp); if (comment_ptr == (char *) -1) /* end-of-file */ break; /* did we get a comment? */ if (comment_ptr) { make_comment (comment_ptr); continue; } /* if we get here, the line was not a comment */ nwords = fetch_words(); /* skip empty lines */ if (nwords == 0) continue; first_word = words[0]; if (equal_strings (first_word, "v")) { if (nwords < 4) { fprintf (stderr, "Too few coordinates: '%s'", str_orig); exit (-1); } #ifdef NEW_LOAD float3 pos; pos.x = atof (words[1]); pos.y = atof (words[2]); pos.z = atof (words[3]); vPosition.push_back(pos); #else x = atof (words[1]); y = atof (words[2]); z = atof (words[3]); if (nwords == 5) { w = atof (words[3]); has_w = 1; } else w = 1.0; make_vertex (x, y, z, w); #endif } else if (equal_strings (first_word, "vn")) { #ifdef NEW_LOAD float3 n; n.x = atof (words[1]); n.y = atof (words[2]); n.z = atof (words[3]); vNormal.push_back(n); has_normals = true; #endif } else if (equal_strings (first_word, "vt")) { #ifdef NEW_LOAD float2 t; t.x = atof (words[1]); t.y = atof (words[2]); vUV.push_back(t); texture_coords = true; #endif } else if (equal_strings (first_word, "f")) { #ifdef NEW_LOAD LoadFace(&words[1],nwords-1); #else make_face (&words[1], nwords-1); #endif } else { fprintf (stderr, "Do not recognize: '%s'\n", str_orig); } } nverts = vVertex.size(); nfaces = vIndex.size()/3; fclose(fp); }
void MakeChar::Setup() { BAM_Guy *pGuy; BAM_Button *pButton; uchar *pback; CelHeader *pbackCH; int x; uint rNumBord; //====================================================== // setup background cel filled with black TRACK_MEM("MakeChar background cel"); gback = ACreateCel(&rNumBack,0,0,320,400,CI_BLACK,100); pback = AGetResData(gback); pbackCH = (CelHeader*)pback; // copy this anim into the dynamic cel that we will use gbackAnim = ALoad(RES_ANIM,8150); CopyCel(pbackCH,0,0,RES_ANIM,8150,1,FALSE); pGuy = &back; pGuy->SetRes(RES_CEL,rNumBack); pGuy->SetPos(0,0); pGuy->SetContext(gSelf); pGuy->Setup(CT_ROST); pGuy->SetPri(100); //pal.FadeToBlack(); pal.Load(8150); // pick a gender catagory switch (ARandom(3)) { case 0: bGlobal.curCat = G_MEN; break; case 1: bGlobal.curCat = G_WOMEN; break; case 2: bGlobal.curCat = G_OTHER; break; } //====================================================== // lets copy in all the borders and boundaries into the background gPortBord = ALoad(RES_ANIM,8154); rNumBord = 8154; CopyCel((CelHeader*)pback,108,67,RES_ANIM,rNumBord,3,TRUE); // Name Frame CopyCel((CelHeader*)pback,108,92,RES_ANIM,rNumBord,1,TRUE); // Portrait Frame CopyCel((CelHeader*)pback,157,92,RES_ANIM,rNumBord,4,TRUE); // Arrow Buttons Frame CopyCel((CelHeader*)pback,108,191,RES_ANIM,rNumBord,5,TRUE); // Gender Buttons Frame CopyCel((CelHeader*)pback,108,222,RES_ANIM,rNumBord,6,TRUE); // Name Buttons Frame CopyCel((CelHeader*)pback,108,253,RES_ANIM,rNumBord,7,TRUE); // 'Done' Button Frame CopyCel((CelHeader*)pback,21,281,RES_ANIM,rNumBord,10,TRUE); // Option Button Frame //============================================= // Write the necessary text into the background pFontMgr->SetRes(9050); SetFontColors(CI_SKIP,64,74); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,1); ASetString(206, 99, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,2); ASetString(206, 116, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,3); ASetString(206, 133, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,4); ASetString(206, 150, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,5); ASetString( 70, 198, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,6); ASetString( 82, 229, pTxt, (uchar *)pbackCH, pbackCH->width, NULL); pFontMgr->SetRes(9052); SetFontColors(CI_SKIP,93,76,74,74,48,CI_BLACK); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,7); pFontMgr->SetString(0,330, pTxt, (uchar *)pbackCH, pbackCH->width, NULL, DG_JUST_CENTER); SetFontColors(CI_SKIP,45,46,47,49,50,CI_BLACK); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,8); pFontMgr->SetString(0,372, pTxt, (uchar *)pbackCH, pbackCH->width, NULL, DG_JUST_CENTER); pFontMgr->SetRes(9050); SetFontColors(CI_SKIP,64,74); switch(bGlobal.curCat) { case G_MEN: sqbRes = MEN_SQB; if(!maxMenNameNum) maxMenNameNum = atoi(sqbMakeChar.Load(MEN_SQB,1)); //add 2 to num to get zero based random num past first sqb used above curNameNum = MyRandom(maxMenNameNum,curNameNum) + 2; break; case G_WOMEN: sqbRes = WOMEN_SQB; if(!maxWomenNameNum) maxWomenNameNum = atoi(sqbMakeChar.Load(WOMEN_SQB,1)); curNameNum = MyRandom(maxWomenNameNum,curNameNum) + 2; break; case G_OTHER: sqbRes = OTHER_SQB; if(!maxOtherNameNum) maxOtherNameNum = atoi(sqbMakeChar.Load(OTHER_SQB,1)); curNameNum = MyRandom(maxOtherNameNum,curNameNum) + 2; break; } pTxt = sqbMakeChar.Load(sqbRes,curNameNum); TRACK_MEM("NameText"); gNameText = AMalloc(20); char *pText = ADerefAs(char, gNameText); strcpy(bGlobal.curName,pTxt); strcpy(pText,pTxt); BAM_Box *pBox = &nameBox; pBox->SetColors(CI_SKIP,64,74,64,74,64,74,155,142); pBox->Create(111, 71, 105, 15, 200, gNameText, 16, gSelf, rNumBack,0,0); pBox->SetupReplies(REPLY_DESELECTED); // let us know when text changes //pBox->Select(TRUE); //makes the box edit active //====================================================== // setup current portrait -randomly init. LoadCover(); LoadFace(); LoadBody(); LoadBanner(); //====================================================== // lets setup up all the buttons uint32 posY[4] = { 95, 112, 129, 146 }; for(x=0; x<4; x++) { // create left arrow button pButton = &leftArrowB[x]; pButton->Create(159, posY[x], 200, RES_ANIM, 8156, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel // create right arrow button pButton = &rightArrowB[x]; pButton->Create(180, posY[x], 200, RES_ANIM, 8157, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel } // disk button pButton = &diskB; pButton->Create(23, 285, 200, RES_ANIM, 129, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &randomCharB; pButton->Create(159, 163, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,9); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &manB; pButton->Create(110, 194, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_ACTIVATED | REPLY_DEACTIVATED); pButton->fIsToggle = TRUE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,10); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); if(bGlobal.curCat == G_MEN) pButton->Select(TRUE); // set button to unselected state - will cause drawing into master cel else pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &womanB; pButton->Create(152, 194, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_ACTIVATED | REPLY_DEACTIVATED); pButton->fIsToggle = TRUE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,11); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); if(bGlobal.curCat == G_WOMEN) pButton->Select(TRUE); // set button to unselected state - will cause drawing into master cel else pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &otherB; pButton->Create(194, 194, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_ACTIVATED | REPLY_DEACTIVATED); pButton->fIsToggle = TRUE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,12); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); if(bGlobal.curCat == G_OTHER) pButton->Select(TRUE); // set button to unselected state - will cause drawing into master cel else pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &customNameB; pButton->Create(110, 225, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,13); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &randomNameB; pButton->Create(152, 225, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,9); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel pButton = &doneB; pButton->Create(110, 256, 200, RES_ANIM, 8158, 1, gSelf); pButton->SetupReplies(REPLY_DESELECTED); pButton->fIsToggle = FALSE; // click-type button pButton->SetOwnerCel(rNumBack); // draws itself into this DCEL, instead of being drawn by Animate() directly pButton->SetTextJustify(DG_JUST_CENTER, DG_JUST_CENTER); pTxt = sqbMakeChar.Load(MAKECHAR_SQB,14); pButton->SetCelText(1, pTxt); pButton->SetColors(1, 93, 90); // inactive colors pButton->SetCelText(2, pTxt); pButton->SetColors(2, 155, 142); // active colors pButton->Draw(); pButton->Select(FALSE); // set button to unselected state - will cause drawing into master cel BAM_Room::Setup(); pGraphMgr->Animate(); pal.FadeUp(); }
/* * Load the glyphs of a paragraph. When shaping with HarfBuzz the glyph indices * have already been determined at this point, as well as the advance values. */ static int LoadGlyphs( filter_t *p_filter, paragraph_t *p_paragraph, bool b_use_glyph_indices, bool b_overwrite_advance ) { if( p_paragraph->i_size <= 0 || p_paragraph->i_runs_count <= 0 ) { msg_Err( p_filter, "LoadGlyphs() invalid parameters. " "Paragraph size: %d. Runs count %d", p_paragraph->i_size, p_paragraph->i_runs_count ); return VLC_EGENERIC; } filter_sys_t *p_sys = p_filter->p_sys; for( int i = 0; i < p_paragraph->i_runs_count; ++i ) { run_desc_t *p_run = p_paragraph->p_runs + i; text_style_t *p_style = p_run->p_style; FT_Face p_face = 0; if( !p_run->p_face ) { p_face = LoadFace( p_filter, p_style ); if( !p_face ) { p_face = p_sys->p_face; p_style = &p_sys->style; p_run->p_style = p_style; } p_run->p_face = p_face; } else p_face = p_run->p_face; if( p_sys->p_stroker ) { double f_outline_thickness = var_InheritInteger( p_filter, "freetype-outline-thickness" ) / 100.0; f_outline_thickness = VLC_CLIP( f_outline_thickness, 0.0, 0.5 ); int i_radius = ( p_style->i_font_size << 6 ) * f_outline_thickness; FT_Stroker_Set( p_sys->p_stroker, i_radius, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0 ); } for( int j = p_run->i_start_offset; j < p_run->i_end_offset; ++j ) { int i_glyph_index; if( b_use_glyph_indices ) i_glyph_index = p_paragraph->pi_glyph_indices[ j ]; else i_glyph_index = FT_Get_Char_Index( p_face, p_paragraph->p_code_points[ j ] ); glyph_bitmaps_t *p_bitmaps = p_paragraph->p_glyph_bitmaps + j; if( FT_Load_Glyph( p_face, i_glyph_index, FT_LOAD_NO_BITMAP | FT_LOAD_DEFAULT ) && FT_Load_Glyph( p_face, i_glyph_index, FT_LOAD_DEFAULT ) ) { p_bitmaps->p_glyph = 0; p_bitmaps->p_outline = 0; p_bitmaps->p_shadow = 0; p_bitmaps->i_x_advance = 0; p_bitmaps->i_y_advance = 0; continue; } if( ( p_style->i_style_flags & STYLE_BOLD ) && !( p_face->style_flags & FT_STYLE_FLAG_BOLD ) ) FT_GlyphSlot_Embolden( p_face->glyph ); if( ( p_style->i_style_flags & STYLE_ITALIC ) && !( p_face->style_flags & FT_STYLE_FLAG_ITALIC ) ) FT_GlyphSlot_Oblique( p_face->glyph ); if( FT_Get_Glyph( p_face->glyph, &p_bitmaps->p_glyph ) ) { p_bitmaps->p_glyph = 0; p_bitmaps->p_outline = 0; p_bitmaps->p_shadow = 0; p_bitmaps->i_x_advance = 0; p_bitmaps->i_y_advance = 0; continue; } if( p_filter->p_sys->p_stroker ) { p_bitmaps->p_outline = p_bitmaps->p_glyph; if( FT_Glyph_StrokeBorder( &p_bitmaps->p_outline, p_filter->p_sys->p_stroker, 0, 0 ) ) p_bitmaps->p_outline = 0; } if( p_filter->p_sys->style.i_shadow_alpha > 0 ) p_bitmaps->p_shadow = p_bitmaps->p_outline ? p_bitmaps->p_outline : p_bitmaps->p_glyph; if( b_overwrite_advance ) { p_bitmaps->i_x_advance = p_face->glyph->advance.x; p_bitmaps->i_y_advance = p_face->glyph->advance.y; } } } return VLC_SUCCESS; }
static int ShapeParagraphHarfBuzz( filter_t *p_filter, paragraph_t **p_old_paragraph ) { paragraph_t *p_paragraph = *p_old_paragraph; paragraph_t *p_new_paragraph = 0; filter_sys_t *p_sys = p_filter->p_sys; int i_total_glyphs = 0; int i_ret = VLC_EGENERIC; if( p_paragraph->i_size <= 0 || p_paragraph->i_runs_count <= 0 ) { msg_Err( p_filter, "ShapeParagraphHarfBuzz() invalid parameters. " "Paragraph size: %d. Runs count %d", p_paragraph->i_size, p_paragraph->i_runs_count ); return VLC_EGENERIC; } for( int i = 0; i < p_paragraph->i_runs_count; ++i ) { run_desc_t *p_run = p_paragraph->p_runs + i; text_style_t *p_style = p_run->p_style; /* * When using HarfBuzz, this is where font faces are loaded. * In the other two paths (shaping with FriBidi or no * shaping at all), faces are loaded in LoadGlyphs() */ FT_Face p_face = 0; if( !p_run->p_face ) { p_face = LoadFace( p_filter, p_style ); if( !p_face ) { p_face = p_sys->p_face; p_style = &p_sys->style; p_run->p_style = p_style; } p_run->p_face = p_face; } else p_face = p_run->p_face; p_run->p_hb_font = hb_ft_font_create( p_face, 0 ); if( !p_run->p_hb_font ) { msg_Err( p_filter, "ShapeParagraphHarfBuzz(): hb_ft_font_create() error" ); goto error; } p_run->p_buffer = hb_buffer_create(); if( !p_run->p_buffer ) { msg_Err( p_filter, "ShapeParagraphHarfBuzz(): hb_buffer_create() error" ); goto error; } hb_buffer_set_direction( p_run->p_buffer, p_run->direction ); hb_buffer_set_script( p_run->p_buffer, p_run->script ); #ifdef __OS2__ hb_buffer_add_utf16( p_run->p_buffer, p_paragraph->p_code_points + p_run->i_start_offset, p_run->i_end_offset - p_run->i_start_offset, 0, p_run->i_end_offset - p_run->i_start_offset ); #else hb_buffer_add_utf32( p_run->p_buffer, p_paragraph->p_code_points + p_run->i_start_offset, p_run->i_end_offset - p_run->i_start_offset, 0, p_run->i_end_offset - p_run->i_start_offset ); #endif hb_shape( p_run->p_hb_font, p_run->p_buffer, 0, 0 ); p_run->p_glyph_infos = hb_buffer_get_glyph_infos( p_run->p_buffer, &p_run->i_glyph_count ); p_run->p_glyph_positions = hb_buffer_get_glyph_positions( p_run->p_buffer, &p_run->i_glyph_count ); if( p_run->i_glyph_count <= 0 ) { msg_Err( p_filter, "ShapeParagraphHarfBuzz() invalid glyph count in shaped run" ); goto error; } i_total_glyphs += p_run->i_glyph_count; } p_new_paragraph = NewParagraph( p_filter, i_total_glyphs, 0, 0, 0, p_paragraph->i_runs_size ); if( !p_new_paragraph ) { i_ret = VLC_ENOMEM; goto error; } p_new_paragraph->paragraph_type = p_paragraph->paragraph_type; int i_index = 0; for( int i = 0; i < p_paragraph->i_runs_count; ++i ) { run_desc_t *p_run = p_paragraph->p_runs + i; hb_glyph_info_t *p_infos = p_run->p_glyph_infos; hb_glyph_position_t *p_positions = p_run->p_glyph_positions; for( unsigned int j = 0; j < p_run->i_glyph_count; ++j ) { /* * HarfBuzz reverses the order of glyphs in RTL runs. We reverse * it again here to keep the glyphs in their logical order. * For line breaking of paragraphs to work correctly, visual * reordering should be done after line breaking has taken * place. */ int i_run_index = p_run->direction == HB_DIRECTION_LTR ? j : p_run->i_glyph_count - 1 - j; int i_source_index = p_infos[ i_run_index ].cluster + p_run->i_start_offset; p_new_paragraph->p_code_points[ i_index ] = 0; p_new_paragraph->pi_glyph_indices[ i_index ] = p_infos[ i_run_index ].codepoint; p_new_paragraph->p_scripts[ i_index ] = p_paragraph->p_scripts[ i_source_index ]; p_new_paragraph->p_types[ i_index ] = p_paragraph->p_types[ i_source_index ]; p_new_paragraph->p_levels[ i_index ] = p_paragraph->p_levels[ i_source_index ]; p_new_paragraph->pp_styles[ i_index ] = p_paragraph->pp_styles[ i_source_index ]; p_new_paragraph->pi_karaoke_bar[ i_index ] = p_paragraph->pi_karaoke_bar[ i_source_index ]; p_new_paragraph->p_glyph_bitmaps[ i_index ].i_x_offset = p_positions[ i_run_index ].x_offset; p_new_paragraph->p_glyph_bitmaps[ i_index ].i_y_offset = p_positions[ i_run_index ].y_offset; p_new_paragraph->p_glyph_bitmaps[ i_index ].i_x_advance = p_positions[ i_run_index ].x_advance; p_new_paragraph->p_glyph_bitmaps[ i_index ].i_y_advance = p_positions[ i_run_index ].y_advance; ++i_index; } if( AddRun( p_filter, p_new_paragraph, i_index - p_run->i_glyph_count, i_index, p_run->p_face ) ) goto error; } for( int i = 0; i < p_paragraph->i_runs_count; ++i ) { hb_font_destroy( p_paragraph->p_runs[ i ].p_hb_font ); hb_buffer_destroy( p_paragraph->p_runs[ i ].p_buffer ); } FreeParagraph( *p_old_paragraph ); *p_old_paragraph = p_new_paragraph; return VLC_SUCCESS; error: for( int i = 0; i < p_paragraph->i_runs_count; ++i ) { if( p_paragraph->p_runs[ i ].p_hb_font ) hb_font_destroy( p_paragraph->p_runs[ i ].p_hb_font ); if( p_paragraph->p_runs[ i ].p_buffer ) hb_buffer_destroy( p_paragraph->p_runs[ i ].p_buffer ); } if( p_new_paragraph ) FreeParagraph( p_new_paragraph ); return i_ret; }
void Menu_FaceMapping::HandleCPUTEvent(int eventID, int controlID, CPUTControl *control) { switch (controlID) { case FaceMappingMenuId_LoadScan: { OPENFILENAMEA ofn; char filename[512]; memset(&ofn, 0, sizeof(OPENFILENAMEA)); filename[0] = 0; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = MySample::Instance->GetHWnd(); ofn.lpstrDefExt = ".obj"; ofn.lpstrFilter = "Obj Files(*.obj)\0*.obj\0\0"; std::string cwd = GetUserDataDirectory(); ofn.lpstrInitialDir = cwd.c_str(); ofn.lpstrTitle = "Select An DDS File"; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; ofn.lpstrFile = filename; ofn.nMaxFile = sizeof(filename) / sizeof(filename[0]); if (GetOpenFileNameA(&ofn)) { LoadFace(std::string(ofn.lpstrFile)); } } break; case FaceMappingMenuId_ScanNewFace: { MenuController_PopTo(&gMenu_Scan, true); } break; case FaceMappingMenuId_SaveSculptedObj: { mSaveSculptedObj = true; } break; case FaceMappingMenuId_ShowRSMesh: { if (IsFaceLoaded()) { gMenu_FaceScanPreview.LoadFaceObj(mObjFilename, true); gMenu_FaceScanPreview.SetFaceScanMode(FaceScanPReviewMode_ViewScan); MenuController_PushMenu(&gMenu_FaceScanPreview); } } break; case FaceMappingMenuId_SliderPitch: case FaceMappingMenuId_SliderYaw: case FaceMappingMenuId_SliderScale: case FaceMappingMenuId_SliderRoll: case FaceMappingMenuId_SliderPhysicalDisplaceOffset: { UpdateTweaksFromGUI(); UpdateGUIFromTweaks(); } break; case FaceMappingMenuId_BaseColor: case FaceMappingMenuId_BaseColor2: { byte *colors = (controlID == FaceMappingMenuId_BaseColor) ? &mTweaks.BlendColorRGB[0] : &mTweaks.BlendColor2RGB[0]; CHOOSECOLOR cc = {}; COLORREF customColors[16]; cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = MySample::Instance->GetHWnd(); cc.rgbResult = RGB(colors[0], colors[1], colors[2]); customColors[0] = RGB(228, 194, 171); customColors[1] = RGB(205, 50, 50); cc.lpCustColors = customColors; cc.Flags = CC_RGBINIT | CC_FULLOPEN; if (ChooseColor(&cc)) { colors[0] = (byte)(cc.rgbResult & 0x000000ff); colors[1] = (byte)((cc.rgbResult & 0x0000ff00) >> 8); colors[2] = (byte)((cc.rgbResult & 0x00ff0000) >> 16); } } break; case FaceMappingMenuId_ResetTweaks: { SetDefaultTweaks(&mTweaks); UpdateGUIFromTweaks(); } break; }