private void CreatePagesWithoutChords(SongViewModel song) { if (String.IsNullOrWhiteSpace(Song.Text)) { Pages.Add(new PresentationPageModel() { Title = song.Title, Text = AppResources.SongTextPresentation_EmptyText, SongKey = song.SongKey, FontSize = FontSize }); return; } Label testLabel = SongTextPresentationView.GetGhostLabelInstance(); string[] allText = song.Text.Split(Environment.NewLine.ToCharArray()); int linesLeft = allText.Length; List <string> leftText = allText.ToList(); while (linesLeft > 0) { int linesFitted = PresentationPageHelper.GetFitPageModel(leftText.ToArray(), testLabel, song.Title, FontSize, song.SongKey); if (linesFitted != -1) { Pages.Add(PresentationPageHelper.PresentationPageModel); linesLeft -= linesFitted + 1; leftText.RemoveRange(0, linesFitted + 1); } } }
void OnTextRecive(AsyncClient source, string text) { if (text != "") { string[] songTitleAndText = text.Split('|'); if (songTitleAndText != null) { Device.BeginInvokeOnMainThread(() => { Label testLabel = SongTextPresentationView.GetGhostLabelInstance(); TitleOfSongWhenConnectedToServer = songTitleAndText[0]; TextOfSongWhenConnectedToServer = songTitleAndText[1]; testLabel.Text = TextOfSongWhenConnectedToServer; testLabel.FontSize = FontSize; FontCalc checkIfShortText = new FontCalc(testLabel, 25, App.ScreenWidth); if (checkIfShortText.TextHeight < App.ScreenHeight * 0.5) { FontSize = checkIfShortText.FontSize; } else { // Calculate the height of the rendered text. FontCalc lowerFontCalc = new FontCalc(testLabel, 10, App.ScreenWidth); FontCalc upperFontCalc = new FontCalc(testLabel, 100, App.ScreenWidth); while (upperFontCalc.FontSize - lowerFontCalc.FontSize > 1) { // Get the average font size of the upper and lower bounds. double fontSize = (lowerFontCalc.FontSize + upperFontCalc.FontSize) / 2; // Check the new text height against the container height. FontCalc newFontCalc = new FontCalc(testLabel, fontSize, App.ScreenWidth); if (newFontCalc.TextHeight > App.ScreenHeight * 0.85) { upperFontCalc = newFontCalc; } else { lowerFontCalc = newFontCalc; } } FontSize = lowerFontCalc.FontSize; } }); } } }
private void CreatePagesWithChords(SongViewModel song) { Label testLabel = SongTextPresentationView.GetGhostLabelInstance(); string[] allText = song.Text.Split(Environment.NewLine.ToCharArray()); string[] allChords = song.Chords.Split(Environment.NewLine.ToCharArray()); int linesLeft = allText.Length; List <string> leftText = allText.ToList(); List <string> leftChords = allChords.ToList(); while (linesLeft > 0) { int linesFitted = PresentationPageHelper.GetFitPageModel(leftText.ToArray(), testLabel, song.Title, FontSize, song.SongKey, addChords: true, chordsToFit: leftChords.ToArray()); if (linesFitted != -1) { Pages.Add(PresentationPageHelper.PresentationPageModel); linesLeft -= linesFitted; leftText.RemoveRange(0, linesFitted); leftChords.RemoveRange(0, linesFitted); } } }