/// <summary> /// get existing or create new one from current font setting /// </summary> /// <param name="glyphIndex"></param> /// <returns></returns> GlyphMeshData InternalGetGlyphMesh(ushort glyphIndex) { if (!_hintGlyphCollection.TryGetCacheGlyph(glyphIndex, out GlyphMeshData glyphMeshData)) { //if not found then create new glyph vxs and cache it _currentGlyphBuilder.SetHintTechnique(_currentHintTech); _currentGlyphBuilder.BuildFromGlyphIndex(glyphIndex, _currentFontSizeInPoints); DynamicOutline dynamicOutline = _currentGlyphBuilder.LatestGlyphFitOutline; //----------------------------------- glyphMeshData = new GlyphMeshData(); if (dynamicOutline != null) { //has dynamic outline data glyphMeshData.avgXOffsetToFit = dynamicOutline.AvgXFitOffset; glyphMeshData.orgBounds = new Bounds( (short)dynamicOutline.MinX, (short)dynamicOutline.MinY, (short)dynamicOutline.MaxX, (short)dynamicOutline.MaxY); glyphMeshData.dynamicOutline = dynamicOutline; } _hintGlyphCollection.RegisterCachedGlyph(glyphIndex, glyphMeshData); //----------------------------------- } return(glyphMeshData); }
/// <summary> /// always create new vxs for this glyph, no caching /// </summary> /// <param name="glyphIndex"></param> /// <returns></returns> public VertexStore GetNewUnFlattenVxs(ushort glyphIndex) { _currentGlyphBuilder.BuildFromGlyphIndex(glyphIndex, _currentFontSizeInPoints); DynamicOutline dynamicOutline = _currentGlyphBuilder.LatestGlyphFitOutline; //----------------------------------- _tovxs.Reset(); float pxscale = _currentTypeface.CalculateScaleToPixelFromPointSize(_currentFontSizeInPoints); if (dynamicOutline != null) { //TODO: review dynamic outline dynamicOutline.GenerateOutput(new ContourToGlyphTranslator(_tovxs), pxscale); //version 3 using (Tools.BorrowVxs(out var v1)) { _tovxs.WriteUnFlattenOutput(v1, 1); return(FlipGlyphUpward ? v1.CreateTrim(s_flipY) : v1.CreateTrim()); } } else { using (Tools.BorrowVxs(out var v1)) { _currentGlyphBuilder.ReadShapes(_tovxs); _tovxs.WriteUnFlattenOutput(v1, 1); //write to temp buffer first //then return(FlipGlyphUpward ? v1.CreateTrim(s_flipY) : v1.CreateTrim()); } } }
public override void OnInspectorGUI() { m_target = (DynamicOutline)target; DrawDefaultInspector(); EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); GUILayout.Label("Combining Meshes currently does not work very well with SkinnedMeshRenderers"); GUILayout.EndHorizontal(); EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Combine Meshes", GUILayout.Height(22))) { GameObject copy = new GameObject(); copy.name = "Combined Mesh of " + m_target.gameObject.name; copy.transform.position = m_target.transform.position; copy.transform.eulerAngles = m_target.transform.eulerAngles; copy.transform.localScale = new Vector3(1, 1, 1); copy.AddComponent <MeshFilter>(); copy.GetComponent <MeshFilter>().mesh = CombineMeshes(copy, m_target.gameObject, false); copy.AddComponent <MeshRenderer>(); } GUILayout.EndHorizontal(); DrawOutlineInspector(); }
/// <summary> /// calculate and create Dynamic outline from original glyph-point /// </summary> /// <param name="glyphPoints"></param> /// <param name="glyphContours"></param> /// <returns></returns> public DynamicOutline CreateDynamicOutline(GlyphPointF[] glyphPoints, ushort[] glyphContours) { //1. convert original glyph point to contour _glyphTxToContourBuilder.Read(glyphPoints, glyphContours); //2. get result as list of contour List <Contour> contours = _contourBuilder.GetContours(); int cnt_count = contours.Count; // if (cnt_count > 0) { //3.before create dynamic contour we must flatten data inside the contour _partFlattener.NSteps = 2; for (int i = 0; i < cnt_count; ++i) { // (flatten each contour with the flattener) contours[i].Flatten(_partFlattener); } //4. after flatten, the we can create fit outline return(CreateDynamicOutline(contours)); } else { return(DynamicOutline.CreateBlankDynamicOutline()); } }
/// <summary> /// get glyph mesh from current font setting /// </summary> /// <param name="glyphIndex"></param> /// <returns></returns> public VertexStore GetGlyphMesh(ushort glyphIndex) { GlyphMeshData glyphMeshData = InternalGetGlyphMesh(glyphIndex); if (glyphMeshData.vxsStore == null) { //build vxs _tovxs.Reset(); float pxscale = _currentTypeface.CalculateScaleToPixelFromPointSize(_currentFontSizeInPoints); DynamicOutline dynamicOutline = glyphMeshData.dynamicOutline; if (dynamicOutline != null) { //TODO: review here aain dynamicOutline.GenerateOutput(new ContourToGlyphTranslator(_tovxs), pxscale); //version 3 using (Tools.BorrowVxs(out var v1)) { _tovxs.WriteOutput(v1); glyphMeshData.vxsStore = FlipGlyphUpward ? v1.CreateTrim(s_flipY) : v1.CreateTrim(); } } else { using (Tools.BorrowVxs(out var v1)) { _currentGlyphBuilder.ReadShapes(_tovxs); _tovxs.WriteOutput(v1); //write to temp buffer first //then glyphMeshData.vxsStore = FlipGlyphUpward ? v1.CreateTrim(s_flipY) : v1.CreateTrim(); } } } if (SimulateOblique) { if (glyphMeshData._synthOblique == null) { //create italic version SimulateQbliqueGlyph(glyphMeshData); } return(glyphMeshData._synthOblique.vxsStore); } else { return(glyphMeshData.vxsStore); } }
private void FixedUpdate() { RaycastHit hit; Ray ray = cam.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0)); if (Physics.Raycast(ray, out hit)) { if (hit.transform.gameObject.layer == 8 && enabledOutline == null) { enabledOutline = hit.transform.GetComponent <DynamicOutline>(); enabledOutline.ShowOutline(true); } else if (hit.transform.gameObject.layer != 8 && enabledOutline != null) { enabledOutline.ShowOutline(false); enabledOutline = null; } } else if (enabledOutline != null) { enabledOutline.ShowOutline(false); enabledOutline = null; } }
protected override void FitCurrentGlyph(Glyph glyph) { //not use interperter so we need to scale it with our mechanism //this demonstrate our auto hint engine *** //you can change this to your own hint engine*** _latestDynamicOutline = null;//reset if (this.UseTrueTypeInstructions) { base.FitCurrentGlyph(glyph); } else { // if (TemporaryDisableCustomFit) { return; } // if (this.UseVerticalHinting) { if (!_fitOutlineCollection.TryGetValue(glyph.GlyphIndex, out _latestDynamicOutline)) { //--------------------------------------------- //test code //GlyphContourBuilder contBuilder = new GlyphContourBuilder(); //contBuilder.Reset(); //int x = 100, y = 120, w = 700, h = 200; //contBuilder.MoveTo(x, y); //contBuilder.LineTo(x + w, y); //contBuilder.LineTo(x + w, y + h); //contBuilder.LineTo(x, y + h); //contBuilder.CloseFigure(); //--------------------------------------------- _latestDynamicOutline = _fitShapeAnalyzer.CreateDynamicOutline( _outputGlyphPoints, _outputContours); //add more information for later scaling process _latestDynamicOutline.OriginalAdvanceWidth = glyph.OriginalAdvanceWidth; _latestDynamicOutline.SetDynamicEdgeOffsetFromMasterOutline(GlyphDynamicEdgeOffset); _latestDynamicOutline.SetOriginalGlyphControlBounds( glyph.Bounds.XMin, glyph.Bounds.YMin, glyph.Bounds.XMax, glyph.Bounds.YMax); //store to our dynamic outline collection //so we can reuse it _fitOutlineCollection.Add(glyph.GlyphIndex, _latestDynamicOutline); //------------------- // _latestDynamicOutline.GenerateOutput(null, Typeface.CalculateScaleToPixel(RecentFontSizeInPixels)); //------------------- } else { if (IsSizeChanged) { _latestDynamicOutline.GenerateOutput(null, Typeface.CalculateScaleToPixel(RecentFontSizeInPixels)); IsSizeChanged = false; } } } } }